temporatry disabling part of code

This commit is contained in:
Kononnable 2019-10-02 14:04:23 +02:00
parent fb529bca0b
commit ab23f71756
9 changed files with 801 additions and 782 deletions

View File

@ -11,6 +11,7 @@ import ColumnInfo from "../oldModels/ColumnInfo";
import IConnectionOptions from "../IConnectionOptions";
import IndexInfo from "../oldModels/IndexInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import { Entity } from "../models/Entity";
export default abstract class AbstractDriver {
public abstract standardPort: number;
@ -159,8 +160,8 @@ export default abstract class AbstractDriver {
public async GetDataFromServer(
connectionOptons: IConnectionOptions
): Promise<EntityInfo[]> {
let dbModel = [] as EntityInfo[];
): Promise<Entity[]> {
let dbModel = [] as Entity[];
await this.ConnectToServer(connectionOptons);
const sqlEscapedSchema = AbstractDriver.escapeCommaSeparatedList(
connectionOptons.schemaName
@ -174,19 +175,20 @@ export default abstract class AbstractDriver {
sqlEscapedSchema,
connectionOptons.databaseName
);
await this.GetIndexesFromEntity(
dbModel,
sqlEscapedSchema,
connectionOptons.databaseName
);
dbModel = await this.GetRelations(
dbModel,
sqlEscapedSchema,
connectionOptons.databaseName
);
// TODO: Uncomment
// await this.GetIndexesFromEntity(
// dbModel,
// sqlEscapedSchema,
// connectionOptons.databaseName
// );
// dbModel = await this.GetRelations(
// dbModel,
// sqlEscapedSchema,
// connectionOptons.databaseName
// );
await this.DisconnectFromServer();
dbModel = AbstractDriver.FindManyToManyRelations(dbModel);
AbstractDriver.FindPrimaryColumnsFromIndexes(dbModel);
// dbModel = AbstractDriver.FindManyToManyRelations(dbModel);
// AbstractDriver.FindPrimaryColumnsFromIndexes(dbModel);
return dbModel;
}
@ -195,18 +197,17 @@ export default abstract class AbstractDriver {
public async GetAllTables(
schema: string,
dbNames: string
): Promise<EntityInfo[]> {
): Promise<Entity[]> {
const response = await this.GetAllTablesQuery(schema, dbNames);
const ret: EntityInfo[] = [] as EntityInfo[];
const ret: Entity[] = [] as Entity[];
response.forEach(val => {
const ent: EntityInfo = new EntityInfo();
ent.tsEntityName = val.TABLE_NAME;
ent.sqlEntityName = val.TABLE_NAME;
ent.Schema = val.TABLE_SCHEMA;
ent.Columns = [] as ColumnInfo[];
ent.Indexes = [] as IndexInfo[];
ent.Database = dbNames.includes(",") ? val.DB_NAME : "";
ret.push(ent);
ret.push({
columns: [],
sqlName: val.TABLE_NAME,
tscName: val.TABLE_NAME,
database: dbNames.includes(",") ? val.DB_NAME : "",
schema: val.TABLE_SCHEMA
});
});
return ret;
}
@ -374,10 +375,10 @@ export default abstract class AbstractDriver {
}
public abstract async GetCoulmnsFromEntity(
entities: EntityInfo[],
entities: Entity[],
schema: string,
dbNames: string
): Promise<EntityInfo[]>;
): Promise<Entity[]>;
public abstract async GetIndexesFromEntity(
entities: EntityInfo[],

View File

@ -10,6 +10,7 @@ import IndexInfo from "../oldModels/IndexInfo";
import IndexColumnInfo from "../oldModels/IndexColumnInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import IConnectionOptions from "../IConnectionOptions";
import { Entity } from "../models/Entity";
export default class MssqlDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.SqlServerDriver({
@ -40,187 +41,189 @@ WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG
};
public async GetCoulmnsFromEntity(
entities: EntityInfo[],
entities: Entity[],
schema: string,
dbNames: string
): Promise<EntityInfo[]> {
const request = new MSSQL.Request(this.Connection);
const response: {
TABLE_NAME: string;
COLUMN_NAME: string;
COLUMN_DEFAULT: string;
IS_NULLABLE: string;
DATA_TYPE: string;
CHARACTER_MAXIMUM_LENGTH: number;
NUMERIC_PRECISION: number;
NUMERIC_SCALE: number;
IsIdentity: number;
IsUnique: number;
}[] = (await request.query(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IsIdentity,
(SELECT count(*)
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
where
tc.CONSTRAINT_TYPE = 'UNIQUE'
and tc.TABLE_NAME = c.TABLE_NAME
and cu.COLUMN_NAME = c.COLUMN_NAME
and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique
FROM INFORMATION_SCHEMA.COLUMNS c
where TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG in (${MssqlDriver.escapeCommaSeparatedList(
dbNames
)})
order by ordinal_position`)).recordset;
entities.forEach(ent => {
response
.filter(filterVal => {
return filterVal.TABLE_NAME === ent.tsEntityName;
})
.forEach(resp => {
const colInfo: ColumnInfo = new ColumnInfo();
colInfo.tsName = resp.COLUMN_NAME;
colInfo.options.name = resp.COLUMN_NAME;
colInfo.options.nullable = resp.IS_NULLABLE === "YES";
colInfo.options.generated = resp.IsIdentity === 1;
colInfo.options.unique = resp.IsUnique === 1;
colInfo.options.default = MssqlDriver.ReturnDefaultValueFunction(
resp.COLUMN_DEFAULT
);
colInfo.options.type = resp.DATA_TYPE as any;
switch (resp.DATA_TYPE) {
case "bigint":
colInfo.tsType = "string";
break;
case "bit":
colInfo.tsType = "boolean";
break;
case "decimal":
colInfo.tsType = "number";
break;
case "int":
colInfo.tsType = "number";
break;
case "money":
colInfo.tsType = "number";
break;
case "numeric":
colInfo.tsType = "number";
break;
case "smallint":
colInfo.tsType = "number";
break;
case "smallmoney":
colInfo.tsType = "number";
break;
case "tinyint":
colInfo.tsType = "number";
break;
case "float":
colInfo.tsType = "number";
break;
case "real":
colInfo.tsType = "number";
break;
case "date":
colInfo.tsType = "Date";
break;
case "datetime2":
colInfo.tsType = "Date";
break;
case "datetime":
colInfo.tsType = "Date";
break;
case "datetimeoffset":
colInfo.tsType = "Date";
break;
case "smalldatetime":
colInfo.tsType = "Date";
break;
case "time":
colInfo.tsType = "Date";
break;
case "char":
colInfo.tsType = "string";
break;
case "text":
colInfo.tsType = "string";
break;
case "varchar":
colInfo.tsType = "string";
break;
case "nchar":
colInfo.tsType = "string";
break;
case "ntext":
colInfo.tsType = "string";
break;
case "nvarchar":
colInfo.tsType = "string";
break;
case "binary":
colInfo.tsType = "Buffer";
break;
case "image":
colInfo.tsType = "Buffer";
break;
case "varbinary":
colInfo.tsType = "Buffer";
break;
case "hierarchyid":
colInfo.tsType = "string";
break;
case "sql_variant":
colInfo.tsType = "string";
break;
case "timestamp":
colInfo.tsType = "Date";
break;
case "uniqueidentifier":
colInfo.tsType = "string";
break;
case "xml":
colInfo.tsType = "string";
break;
case "geometry":
colInfo.tsType = "string";
break;
case "geography":
colInfo.tsType = "string";
break;
default:
TomgUtils.LogError(
`Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}`
);
break;
}
): Promise<Entity[]> {
throw new Error();
// TODO: Remove
// const request = new MSSQL.Request(this.Connection);
// const response: {
// TABLE_NAME: string;
// COLUMN_NAME: string;
// COLUMN_DEFAULT: string;
// IS_NULLABLE: string;
// DATA_TYPE: string;
// CHARACTER_MAXIMUM_LENGTH: number;
// NUMERIC_PRECISION: number;
// NUMERIC_SCALE: number;
// IsIdentity: number;
// IsUnique: number;
// }[] = (await request.query(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
// DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
// COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IsIdentity,
// (SELECT count(*)
// FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
// inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
// on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
// where
// tc.CONSTRAINT_TYPE = 'UNIQUE'
// and tc.TABLE_NAME = c.TABLE_NAME
// and cu.COLUMN_NAME = c.COLUMN_NAME
// and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique
// FROM INFORMATION_SCHEMA.COLUMNS c
// where TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG in (${MssqlDriver.escapeCommaSeparatedList(
// dbNames
// )})
// order by ordinal_position`)).recordset;
// entities.forEach(ent => {
// response
// .filter(filterVal => {
// return filterVal.TABLE_NAME === ent.tsEntityName;
// })
// .forEach(resp => {
// const colInfo: ColumnInfo = new ColumnInfo();
// colInfo.tsName = resp.COLUMN_NAME;
// colInfo.options.name = resp.COLUMN_NAME;
// colInfo.options.nullable = resp.IS_NULLABLE === "YES";
// colInfo.options.generated = resp.IsIdentity === 1;
// colInfo.options.unique = resp.IsUnique === 1;
// colInfo.options.default = MssqlDriver.ReturnDefaultValueFunction(
// resp.COLUMN_DEFAULT
// );
// colInfo.options.type = resp.DATA_TYPE as any;
// switch (resp.DATA_TYPE) {
// case "bigint":
// colInfo.tsType = "string";
// break;
// case "bit":
// colInfo.tsType = "boolean";
// break;
// case "decimal":
// colInfo.tsType = "number";
// break;
// case "int":
// colInfo.tsType = "number";
// break;
// case "money":
// colInfo.tsType = "number";
// break;
// case "numeric":
// colInfo.tsType = "number";
// break;
// case "smallint":
// colInfo.tsType = "number";
// break;
// case "smallmoney":
// colInfo.tsType = "number";
// break;
// case "tinyint":
// colInfo.tsType = "number";
// break;
// case "float":
// colInfo.tsType = "number";
// break;
// case "real":
// colInfo.tsType = "number";
// break;
// case "date":
// colInfo.tsType = "Date";
// break;
// case "datetime2":
// colInfo.tsType = "Date";
// break;
// case "datetime":
// colInfo.tsType = "Date";
// break;
// case "datetimeoffset":
// colInfo.tsType = "Date";
// break;
// case "smalldatetime":
// colInfo.tsType = "Date";
// break;
// case "time":
// colInfo.tsType = "Date";
// break;
// case "char":
// colInfo.tsType = "string";
// break;
// case "text":
// colInfo.tsType = "string";
// break;
// case "varchar":
// colInfo.tsType = "string";
// break;
// case "nchar":
// colInfo.tsType = "string";
// break;
// case "ntext":
// colInfo.tsType = "string";
// break;
// case "nvarchar":
// colInfo.tsType = "string";
// break;
// case "binary":
// colInfo.tsType = "Buffer";
// break;
// case "image":
// colInfo.tsType = "Buffer";
// break;
// case "varbinary":
// colInfo.tsType = "Buffer";
// break;
// case "hierarchyid":
// colInfo.tsType = "string";
// break;
// case "sql_variant":
// colInfo.tsType = "string";
// break;
// case "timestamp":
// colInfo.tsType = "Date";
// break;
// case "uniqueidentifier":
// colInfo.tsType = "string";
// break;
// case "xml":
// colInfo.tsType = "string";
// break;
// case "geometry":
// colInfo.tsType = "string";
// break;
// case "geography":
// colInfo.tsType = "string";
// break;
// default:
// TomgUtils.LogError(
// `Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}`
// );
// break;
// }
if (
this.ColumnTypesWithPrecision.some(
v => v === colInfo.options.type
)
) {
colInfo.options.precision = resp.NUMERIC_PRECISION;
colInfo.options.scale = resp.NUMERIC_SCALE;
}
if (
this.ColumnTypesWithLength.some(
v => v === colInfo.options.type
)
) {
colInfo.options.length =
resp.CHARACTER_MAXIMUM_LENGTH > 0
? resp.CHARACTER_MAXIMUM_LENGTH
: undefined;
}
// if (
// this.ColumnTypesWithPrecision.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.precision = resp.NUMERIC_PRECISION;
// colInfo.options.scale = resp.NUMERIC_SCALE;
// }
// if (
// this.ColumnTypesWithLength.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.length =
// resp.CHARACTER_MAXIMUM_LENGTH > 0
// ? resp.CHARACTER_MAXIMUM_LENGTH
// : undefined;
// }
if (colInfo.options.type) {
ent.Columns.push(colInfo);
}
});
});
return entities;
// if (colInfo.options.type) {
// ent.Columns.push(colInfo);
// }
// });
// });
// return entities;
}
public async GetIndexesFromEntity(

View File

@ -10,6 +10,8 @@ import IndexInfo from "../oldModels/IndexInfo";
import IndexColumnInfo from "../oldModels/IndexColumnInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import IConnectionOptions from "../IConnectionOptions";
import { Entity } from "../models/Entity";
import { Column } from "../models/Column";
export default class MysqlDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.MysqlDriver({
@ -41,10 +43,10 @@ export default class MysqlDriver extends AbstractDriver {
};
public async GetCoulmnsFromEntity(
entities: EntityInfo[],
entities: Entity[],
schema: string,
dbNames: string
): Promise<EntityInfo[]> {
): Promise<Entity[]> {
const response = await this.ExecQuery<{
TABLE_NAME: string;
COLUMN_NAME: string;
@ -66,150 +68,149 @@ export default class MysqlDriver extends AbstractDriver {
order by ordinal_position`);
entities.forEach(ent => {
response
.filter(filterVal => filterVal.TABLE_NAME === ent.tsEntityName)
.filter(filterVal => filterVal.TABLE_NAME === ent.tscName)
.forEach(resp => {
const colInfo: ColumnInfo = new ColumnInfo();
colInfo.tsName = resp.COLUMN_NAME;
colInfo.options.name = resp.COLUMN_NAME;
colInfo.options.nullable = resp.IS_NULLABLE === "YES";
colInfo.options.generated = resp.IsIdentity === 1;
colInfo.options.unique = resp.COLUMN_KEY === "UNI";
colInfo.options.default = MysqlDriver.ReturnDefaultValueFunction(
const tscName = resp.COLUMN_NAME;
let tscType = "";
const options: Partial<Column["options"]> = {};
options.name = resp.COLUMN_NAME;
options.nullable = resp.IS_NULLABLE === "YES";
const generated = resp.IsIdentity === 1 ? true : undefined;
options.unique = resp.COLUMN_KEY === "UNI";
options.default = MysqlDriver.ReturnDefaultValueFunction(
resp.COLUMN_DEFAULT
);
colInfo.options.type = resp.DATA_TYPE as any;
colInfo.options.unsigned = resp.COLUMN_TYPE.endsWith(
" unsigned"
);
options.type = resp.DATA_TYPE as any;
options.unsigned = resp.COLUMN_TYPE.endsWith(" unsigned");
switch (resp.DATA_TYPE) {
case "int":
colInfo.tsType = "number";
tscType = "number";
break;
case "bit":
if (resp.COLUMN_TYPE === "bit(1)") {
colInfo.options.width = 1;
colInfo.tsType = "boolean";
options.width = 1;
tscType = "boolean";
} else {
colInfo.tsType = "number";
tscType = "number";
}
break;
case "tinyint":
if (resp.COLUMN_TYPE === "tinyint(1)") {
colInfo.options.width = 1;
colInfo.tsType = "boolean";
options.width = 1;
tscType = "boolean";
} else {
colInfo.tsType = "number";
tscType = "number";
}
break;
case "smallint":
colInfo.tsType = "number";
tscType = "number";
break;
case "mediumint":
colInfo.tsType = "number";
tscType = "number";
break;
case "bigint":
colInfo.tsType = "string";
tscType = "string";
break;
case "float":
colInfo.tsType = "number";
tscType = "number";
break;
case "double":
colInfo.tsType = "number";
tscType = "number";
break;
case "decimal":
colInfo.tsType = "string";
tscType = "string";
break;
case "date":
colInfo.tsType = "string";
tscType = "string";
break;
case "datetime":
colInfo.tsType = "Date";
tscType = "Date";
break;
case "timestamp":
colInfo.tsType = "Date";
tscType = "Date";
break;
case "time":
colInfo.tsType = "string";
tscType = "string";
break;
case "year":
colInfo.tsType = "number";
tscType = "number";
break;
case "char":
colInfo.tsType = "string";
tscType = "string";
break;
case "varchar":
colInfo.tsType = "string";
tscType = "string";
break;
case "blob":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "text":
colInfo.tsType = "string";
tscType = "string";
break;
case "tinyblob":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "tinytext":
colInfo.tsType = "string";
tscType = "string";
break;
case "mediumblob":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "mediumtext":
colInfo.tsType = "string";
tscType = "string";
break;
case "longblob":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "longtext":
colInfo.tsType = "string";
tscType = "string";
break;
case "enum":
colInfo.tsType = resp.COLUMN_TYPE.substring(
tscType = resp.COLUMN_TYPE.substring(
5,
resp.COLUMN_TYPE.length - 1
)
.replace(/'/gi, '"')
.replace(/","/gi, '" | "');
colInfo.options.enum = resp.COLUMN_TYPE.substring(
options.enum = resp.COLUMN_TYPE.substring(
5,
resp.COLUMN_TYPE.length - 1
).replace(/'/gi, '"');
break;
case "json":
colInfo.tsType = "object";
tscType = "object";
break;
case "binary":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "varbinary":
colInfo.tsType = "Buffer";
tscType = "Buffer";
break;
case "geometry":
colInfo.tsType = "string";
tscType = "string";
break;
case "point":
colInfo.tsType = "string";
tscType = "string";
break;
case "linestring":
colInfo.tsType = "string";
tscType = "string";
break;
case "polygon":
colInfo.tsType = "string";
tscType = "string";
break;
case "multipoint":
colInfo.tsType = "string";
tscType = "string";
break;
case "multilinestring":
colInfo.tsType = "string";
tscType = "string";
break;
case "multipolygon":
colInfo.tsType = "string";
tscType = "string";
break;
case "geometrycollection":
case "geomcollection":
colInfo.options.type = "geometrycollection";
colInfo.tsType = "string";
options.type = "geometrycollection";
tscType = "string";
break;
default:
TomgUtils.LogError(
@ -219,37 +220,39 @@ export default class MysqlDriver extends AbstractDriver {
}
if (
this.ColumnTypesWithPrecision.some(
v => v === colInfo.options.type
v => v === options.type
)
) {
colInfo.options.precision = resp.NUMERIC_PRECISION;
colInfo.options.scale = resp.NUMERIC_SCALE;
options.precision = resp.NUMERIC_PRECISION;
options.scale = resp.NUMERIC_SCALE;
}
if (
this.ColumnTypesWithLength.some(
v => v === colInfo.options.type
)
this.ColumnTypesWithLength.some(v => v === options.type)
) {
colInfo.options.length =
options.length =
resp.CHARACTER_MAXIMUM_LENGTH > 0
? resp.CHARACTER_MAXIMUM_LENGTH
: undefined;
}
if (
this.ColumnTypesWithWidth.some(
v =>
v === colInfo.options.type &&
colInfo.tsType !== "boolean"
v => v === options.type && tscType !== "boolean"
)
) {
colInfo.options.width =
options.width =
resp.CHARACTER_MAXIMUM_LENGTH > 0
? resp.CHARACTER_MAXIMUM_LENGTH
: undefined;
}
if (colInfo.options.type) {
ent.Columns.push(colInfo);
if (options.type) {
ent.columns.push({
generated,
options,
tscName,
tscType,
primary
});
}
});
});
@ -463,11 +466,11 @@ export default class MysqlDriver extends AbstractDriver {
}
private static ReturnDefaultValueFunction(
defVal: string | null
): string | null {
defVal: string | undefined
): string | undefined {
let defaultValue = defVal;
if (!defaultValue || defaultValue === "NULL") {
return null;
return undefined;
}
if (defaultValue.toLowerCase() === "current_timestamp()") {
defaultValue = "CURRENT_TIMESTAMP";

View File

@ -8,6 +8,7 @@ import IndexInfo from "../oldModels/IndexInfo";
import IndexColumnInfo from "../oldModels/IndexColumnInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import IConnectionOptions from "../IConnectionOptions";
import { Entity } from "../models/Entity";
export default class OracleDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.OracleDriver({
@ -47,163 +48,163 @@ export default class OracleDriver extends AbstractDriver {
return response;
};
public async GetCoulmnsFromEntity(
entities: EntityInfo[]
): Promise<EntityInfo[]> {
const response: {
TABLE_NAME: string;
COLUMN_NAME: string;
DATA_DEFAULT: string;
NULLABLE: string;
DATA_TYPE: string;
DATA_LENGTH: number;
DATA_PRECISION: number;
DATA_SCALE: number;
IDENTITY_COLUMN: string;
IS_UNIQUE: number;
}[] = (await this.Connection
.execute(`SELECT utc.TABLE_NAME, utc.COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH,
DATA_PRECISION, DATA_SCALE, IDENTITY_COLUMN,
(select count(*) from USER_CONS_COLUMNS ucc
JOIN USER_CONSTRAINTS uc ON uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME and uc.CONSTRAINT_TYPE='U'
where ucc.column_name = utc.COLUMN_NAME AND ucc.table_name = utc.TABLE_NAME) IS_UNIQUE
FROM USER_TAB_COLUMNS utc`)).rows!;
public async GetCoulmnsFromEntity(entities: Entity[]): Promise<Entity[]> {
throw new Error();
// TODO: Remove
// const response: {
// TABLE_NAME: string;
// COLUMN_NAME: string;
// DATA_DEFAULT: string;
// NULLABLE: string;
// DATA_TYPE: string;
// DATA_LENGTH: number;
// DATA_PRECISION: number;
// DATA_SCALE: number;
// IDENTITY_COLUMN: string;
// IS_UNIQUE: number;
// }[] = (await this.Connection
// .execute(`SELECT utc.TABLE_NAME, utc.COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH,
// DATA_PRECISION, DATA_SCALE, IDENTITY_COLUMN,
// (select count(*) from USER_CONS_COLUMNS ucc
// JOIN USER_CONSTRAINTS uc ON uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME and uc.CONSTRAINT_TYPE='U'
// where ucc.column_name = utc.COLUMN_NAME AND ucc.table_name = utc.TABLE_NAME) IS_UNIQUE
// FROM USER_TAB_COLUMNS utc`)).rows!;
entities.forEach(ent => {
response
.filter(filterVal => filterVal.TABLE_NAME === ent.tsEntityName)
.forEach(resp => {
const colInfo: ColumnInfo = new ColumnInfo();
colInfo.tsName = resp.COLUMN_NAME;
colInfo.options.name = resp.COLUMN_NAME;
colInfo.options.nullable = resp.NULLABLE === "Y";
colInfo.options.generated = resp.IDENTITY_COLUMN === "YES";
colInfo.options.default =
!resp.DATA_DEFAULT || resp.DATA_DEFAULT.includes('"')
? null
: OracleDriver.ReturnDefaultValueFunction(
resp.DATA_DEFAULT
);
colInfo.options.unique = resp.IS_UNIQUE > 0;
const DATA_TYPE = resp.DATA_TYPE.replace(/\([0-9]+\)/g, "");
colInfo.options.type = DATA_TYPE.toLowerCase() as any;
switch (DATA_TYPE.toLowerCase()) {
case "char":
colInfo.tsType = "string";
break;
case "nchar":
colInfo.tsType = "string";
break;
case "nvarchar2":
colInfo.tsType = "string";
break;
case "varchar2":
colInfo.tsType = "string";
break;
case "long":
colInfo.tsType = "string";
break;
case "raw":
colInfo.tsType = "Buffer";
break;
case "long raw":
colInfo.tsType = "Buffer";
break;
case "number":
colInfo.tsType = "number";
break;
case "numeric":
colInfo.tsType = "number";
break;
case "float":
colInfo.tsType = "number";
break;
case "dec":
colInfo.tsType = "number";
break;
case "decimal":
colInfo.tsType = "number";
break;
case "integer":
colInfo.tsType = "number";
break;
case "int":
colInfo.tsType = "number";
break;
case "smallint":
colInfo.tsType = "number";
break;
case "real":
colInfo.tsType = "number";
break;
case "double precision":
colInfo.tsType = "number";
break;
case "date":
colInfo.tsType = "Date";
break;
case "timestamp":
colInfo.tsType = "Date";
break;
case "timestamp with time zone":
colInfo.tsType = "Date";
break;
case "timestamp with local time zone":
colInfo.tsType = "Date";
break;
case "interval year to month":
colInfo.tsType = "string";
break;
case "interval day to second":
colInfo.tsType = "string";
break;
case "bfile":
colInfo.tsType = "Buffer";
break;
case "blob":
colInfo.tsType = "Buffer";
break;
case "clob":
colInfo.tsType = "string";
break;
case "nclob":
colInfo.tsType = "string";
break;
case "rowid":
colInfo.tsType = "number";
break;
case "urowid":
colInfo.tsType = "number";
break;
default:
TomgUtils.LogError(
`Unknown column type:${DATA_TYPE}`
);
break;
}
if (
this.ColumnTypesWithPrecision.some(
v => v === colInfo.options.type
)
) {
colInfo.options.precision = resp.DATA_PRECISION;
colInfo.options.scale = resp.DATA_SCALE;
}
if (
this.ColumnTypesWithLength.some(
v => v === colInfo.options.type
)
) {
colInfo.options.length =
resp.DATA_LENGTH > 0 ? resp.DATA_LENGTH : undefined;
}
// entities.forEach(ent => {
// response
// .filter(filterVal => filterVal.TABLE_NAME === ent.tsEntityName)
// .forEach(resp => {
// const colInfo: ColumnInfo = new ColumnInfo();
// colInfo.tsName = resp.COLUMN_NAME;
// colInfo.options.name = resp.COLUMN_NAME;
// colInfo.options.nullable = resp.NULLABLE === "Y";
// colInfo.options.generated = resp.IDENTITY_COLUMN === "YES";
// colInfo.options.default =
// !resp.DATA_DEFAULT || resp.DATA_DEFAULT.includes('"')
// ? null
// : OracleDriver.ReturnDefaultValueFunction(
// resp.DATA_DEFAULT
// );
// colInfo.options.unique = resp.IS_UNIQUE > 0;
// const DATA_TYPE = resp.DATA_TYPE.replace(/\([0-9]+\)/g, "");
// colInfo.options.type = DATA_TYPE.toLowerCase() as any;
// switch (DATA_TYPE.toLowerCase()) {
// case "char":
// colInfo.tsType = "string";
// break;
// case "nchar":
// colInfo.tsType = "string";
// break;
// case "nvarchar2":
// colInfo.tsType = "string";
// break;
// case "varchar2":
// colInfo.tsType = "string";
// break;
// case "long":
// colInfo.tsType = "string";
// break;
// case "raw":
// colInfo.tsType = "Buffer";
// break;
// case "long raw":
// colInfo.tsType = "Buffer";
// break;
// case "number":
// colInfo.tsType = "number";
// break;
// case "numeric":
// colInfo.tsType = "number";
// break;
// case "float":
// colInfo.tsType = "number";
// break;
// case "dec":
// colInfo.tsType = "number";
// break;
// case "decimal":
// colInfo.tsType = "number";
// break;
// case "integer":
// colInfo.tsType = "number";
// break;
// case "int":
// colInfo.tsType = "number";
// break;
// case "smallint":
// colInfo.tsType = "number";
// break;
// case "real":
// colInfo.tsType = "number";
// break;
// case "double precision":
// colInfo.tsType = "number";
// break;
// case "date":
// colInfo.tsType = "Date";
// break;
// case "timestamp":
// colInfo.tsType = "Date";
// break;
// case "timestamp with time zone":
// colInfo.tsType = "Date";
// break;
// case "timestamp with local time zone":
// colInfo.tsType = "Date";
// break;
// case "interval year to month":
// colInfo.tsType = "string";
// break;
// case "interval day to second":
// colInfo.tsType = "string";
// break;
// case "bfile":
// colInfo.tsType = "Buffer";
// break;
// case "blob":
// colInfo.tsType = "Buffer";
// break;
// case "clob":
// colInfo.tsType = "string";
// break;
// case "nclob":
// colInfo.tsType = "string";
// break;
// case "rowid":
// colInfo.tsType = "number";
// break;
// case "urowid":
// colInfo.tsType = "number";
// break;
// default:
// TomgUtils.LogError(
// `Unknown column type:${DATA_TYPE}`
// );
// break;
// }
// if (
// this.ColumnTypesWithPrecision.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.precision = resp.DATA_PRECISION;
// colInfo.options.scale = resp.DATA_SCALE;
// }
// if (
// this.ColumnTypesWithLength.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.length =
// resp.DATA_LENGTH > 0 ? resp.DATA_LENGTH : undefined;
// }
if (colInfo.options.type) {
ent.Columns.push(colInfo);
}
});
});
return entities;
// if (colInfo.options.type) {
// ent.Columns.push(colInfo);
// }
// });
// });
// return entities;
}
public async GetIndexesFromEntity(

View File

@ -10,6 +10,7 @@ import IndexInfo from "../oldModels/IndexInfo";
import IndexColumnInfo from "../oldModels/IndexColumnInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import IConnectionOptions from "../IConnectionOptions";
import { Entity } from "../models/Entity";
export default class PostgresDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.PostgresDriver({
@ -36,126 +37,128 @@ export default class PostgresDriver extends AbstractDriver {
};
public async GetCoulmnsFromEntity(
entities: EntityInfo[],
entities: Entity[],
schema: string
): Promise<EntityInfo[]> {
const response: {
table_name: string;
column_name: string;
udt_name: string;
column_default: string;
is_nullable: string;
data_type: string;
character_maximum_length: number;
numeric_precision: number;
numeric_scale: number;
isidentity: string;
isunique: string;
enumvalues: string | null;
}[] = (await this.Connection
.query(`SELECT table_name,column_name,udt_name,column_default,is_nullable,
data_type,character_maximum_length,numeric_precision,numeric_scale,
case when column_default LIKE 'nextval%' then 'YES' else 'NO' end isidentity,
(SELECT count(*)
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
where
tc.CONSTRAINT_TYPE = 'UNIQUE'
and tc.TABLE_NAME = c.TABLE_NAME
and cu.COLUMN_NAME = c.COLUMN_NAME
and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique,
(SELECT
string_agg(enumlabel, ',')
FROM "pg_enum" "e"
INNER JOIN "pg_type" "t" ON "t"."oid" = "e"."enumtypid"
INNER JOIN "pg_namespace" "n" ON "n"."oid" = "t"."typnamespace"
WHERE "n"."nspname" = table_schema AND "t"."typname"=udt_name
) enumValues
FROM INFORMATION_SCHEMA.COLUMNS c
where table_schema in (${schema})
order by ordinal_position`)).rows;
entities.forEach(ent => {
response
.filter(filterVal => filterVal.table_name === ent.tsEntityName)
.forEach(resp => {
const colInfo: ColumnInfo = new ColumnInfo();
colInfo.tsName = resp.column_name;
colInfo.options.name = resp.column_name;
colInfo.options.nullable = resp.is_nullable === "YES";
colInfo.options.generated = resp.isidentity === "YES";
colInfo.options.unique = resp.isunique === "1";
colInfo.options.default = colInfo.options.generated
? null
: PostgresDriver.ReturnDefaultValueFunction(
resp.column_default
);
): Promise<Entity[]> {
throw new Error();
// TODO: Remove
// const response: {
// table_name: string;
// column_name: string;
// udt_name: string;
// column_default: string;
// is_nullable: string;
// data_type: string;
// character_maximum_length: number;
// numeric_precision: number;
// numeric_scale: number;
// isidentity: string;
// isunique: string;
// enumvalues: string | null;
// }[] = (await this.Connection
// .query(`SELECT table_name,column_name,udt_name,column_default,is_nullable,
// data_type,character_maximum_length,numeric_precision,numeric_scale,
// case when column_default LIKE 'nextval%' then 'YES' else 'NO' end isidentity,
// (SELECT count(*)
// FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
// inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
// on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
// where
// tc.CONSTRAINT_TYPE = 'UNIQUE'
// and tc.TABLE_NAME = c.TABLE_NAME
// and cu.COLUMN_NAME = c.COLUMN_NAME
// and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique,
// (SELECT
// string_agg(enumlabel, ',')
// FROM "pg_enum" "e"
// INNER JOIN "pg_type" "t" ON "t"."oid" = "e"."enumtypid"
// INNER JOIN "pg_namespace" "n" ON "n"."oid" = "t"."typnamespace"
// WHERE "n"."nspname" = table_schema AND "t"."typname"=udt_name
// ) enumValues
// FROM INFORMATION_SCHEMA.COLUMNS c
// where table_schema in (${schema})
// order by ordinal_position`)).rows;
// entities.forEach(ent => {
// response
// .filter(filterVal => filterVal.table_name === ent.tsEntityName)
// .forEach(resp => {
// const colInfo: ColumnInfo = new ColumnInfo();
// colInfo.tsName = resp.column_name;
// colInfo.options.name = resp.column_name;
// colInfo.options.nullable = resp.is_nullable === "YES";
// colInfo.options.generated = resp.isidentity === "YES";
// colInfo.options.unique = resp.isunique === "1";
// colInfo.options.default = colInfo.options.generated
// ? null
// : PostgresDriver.ReturnDefaultValueFunction(
// resp.column_default
// );
const columnTypes = this.MatchColumnTypes(
resp.data_type,
resp.udt_name,
resp.enumvalues
);
if (!columnTypes.sqlType || !columnTypes.tsType) {
if (
resp.data_type === "USER-DEFINED" ||
resp.data_type === "ARRAY"
) {
TomgUtils.LogError(
`Unknown ${resp.data_type} column type: ${resp.udt_name} table name: ${resp.table_name} column name: ${resp.column_name}`
);
} else {
TomgUtils.LogError(
`Unknown column type: ${resp.data_type} table name: ${resp.table_name} column name: ${resp.column_name}`
);
}
return;
}
colInfo.options.type = columnTypes.sqlType as any;
colInfo.tsType = columnTypes.tsType;
colInfo.options.array = columnTypes.isArray;
colInfo.options.enum = columnTypes.enumValues;
if (colInfo.options.array) {
colInfo.tsType = colInfo.tsType
.split("|")
.map(x => `${x.replace("|", "").trim()}[]`)
.join(" | ") as any;
}
// const columnTypes = this.MatchColumnTypes(
// resp.data_type,
// resp.udt_name,
// resp.enumvalues
// );
// if (!columnTypes.sqlType || !columnTypes.tsType) {
// if (
// resp.data_type === "USER-DEFINED" ||
// resp.data_type === "ARRAY"
// ) {
// TomgUtils.LogError(
// `Unknown ${resp.data_type} column type: ${resp.udt_name} table name: ${resp.table_name} column name: ${resp.column_name}`
// );
// } else {
// TomgUtils.LogError(
// `Unknown column type: ${resp.data_type} table name: ${resp.table_name} column name: ${resp.column_name}`
// );
// }
// return;
// }
// colInfo.options.type = columnTypes.sqlType as any;
// colInfo.tsType = columnTypes.tsType;
// colInfo.options.array = columnTypes.isArray;
// colInfo.options.enum = columnTypes.enumValues;
// if (colInfo.options.array) {
// colInfo.tsType = colInfo.tsType
// .split("|")
// .map(x => `${x.replace("|", "").trim()}[]`)
// .join(" | ") as any;
// }
if (
this.ColumnTypesWithPrecision.some(
v => v === colInfo.options.type
)
) {
colInfo.options.precision = resp.numeric_precision;
colInfo.options.scale = resp.numeric_scale;
}
if (
this.ColumnTypesWithLength.some(
v => v === colInfo.options.type
)
) {
colInfo.options.length =
resp.character_maximum_length > 0
? resp.character_maximum_length
: undefined;
}
if (
this.ColumnTypesWithWidth.some(
v => v === colInfo.options.type
)
) {
colInfo.options.width =
resp.character_maximum_length > 0
? resp.character_maximum_length
: undefined;
}
if (colInfo.options.type && colInfo.tsType) {
ent.Columns.push(colInfo);
}
});
});
return entities;
// if (
// this.ColumnTypesWithPrecision.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.precision = resp.numeric_precision;
// colInfo.options.scale = resp.numeric_scale;
// }
// if (
// this.ColumnTypesWithLength.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.length =
// resp.character_maximum_length > 0
// ? resp.character_maximum_length
// : undefined;
// }
// if (
// this.ColumnTypesWithWidth.some(
// v => v === colInfo.options.type
// )
// ) {
// colInfo.options.width =
// resp.character_maximum_length > 0
// ? resp.character_maximum_length
// : undefined;
// }
// if (colInfo.options.type && colInfo.tsType) {
// ent.Columns.push(colInfo);
// }
// });
// });
// return entities;
}
public MatchColumnTypes(

View File

@ -10,6 +10,7 @@ import IndexInfo from "../oldModels/IndexInfo";
import IndexColumnInfo from "../oldModels/IndexColumnInfo";
import RelationTempInfo from "../oldModels/RelationTempInfo";
import IConnectionOptions from "../IConnectionOptions";
import { Entity } from "../models/Entity";
export default class SqliteDriver extends AbstractDriver {
public defaultValues: DataTypeDefaults = new TypeormDriver.SqliteDriver({
@ -30,190 +31,190 @@ export default class SqliteDriver extends AbstractDriver {
public GetAllTablesQuery: any;
public async GetAllTables(): Promise<EntityInfo[]> {
const ret: EntityInfo[] = [] as EntityInfo[];
public async GetAllTables(): Promise<Entity[]> {
const ret: Entity[] = [] as Entity[];
const rows = await this.ExecQuery<{ tbl_name: string; sql: string }>(
`SELECT tbl_name, sql FROM "sqlite_master" WHERE "type" = 'table' AND name NOT LIKE 'sqlite_%'`
);
rows.forEach(val => {
const ent: EntityInfo = new EntityInfo();
ent.tsEntityName = val.tbl_name;
ent.Columns = [] as ColumnInfo[];
ent.Indexes = [] as IndexInfo[];
if (val.sql.includes("AUTOINCREMENT")) {
this.tablesWithGeneratedPrimaryKey.push(ent.tsEntityName);
this.tablesWithGeneratedPrimaryKey.push(val.tbl_name);
}
ret.push(ent);
ret.push({
columns: [],
sqlName: val.tbl_name,
tscName: val.tbl_name
});
});
return ret;
}
public async GetCoulmnsFromEntity(
entities: EntityInfo[]
): Promise<EntityInfo[]> {
await Promise.all(
entities.map(async ent => {
const response = await this.ExecQuery<{
cid: number;
name: string;
type: string;
notnull: number;
dflt_value: string;
pk: number;
}>(`PRAGMA table_info('${ent.tsEntityName}');`);
response.forEach(resp => {
const colInfo: ColumnInfo = new ColumnInfo();
colInfo.tsName = resp.name;
colInfo.options.name = resp.name;
colInfo.options.nullable = resp.notnull === 0;
colInfo.options.primary = resp.pk > 0;
colInfo.options.default = SqliteDriver.ReturnDefaultValueFunction(
resp.dflt_value
);
colInfo.options.type = resp.type
.replace(/\([0-9 ,]+\)/g, "")
.toLowerCase()
.trim() as any;
colInfo.options.generated =
colInfo.options.primary &&
this.tablesWithGeneratedPrimaryKey.includes(
ent.tsEntityName
);
switch (colInfo.options.type) {
case "int":
colInfo.tsType = "number";
break;
case "integer":
colInfo.tsType = "number";
break;
case "int2":
colInfo.tsType = "number";
break;
case "int8":
colInfo.tsType = "number";
break;
case "tinyint":
colInfo.tsType = "number";
break;
case "smallint":
colInfo.tsType = "number";
break;
case "mediumint":
colInfo.tsType = "number";
break;
case "bigint":
colInfo.tsType = "string";
break;
case "unsigned big int":
colInfo.tsType = "string";
break;
case "character":
colInfo.tsType = "string";
break;
case "varchar":
colInfo.tsType = "string";
break;
case "varying character":
colInfo.tsType = "string";
break;
case "nchar":
colInfo.tsType = "string";
break;
case "native character":
colInfo.tsType = "string";
break;
case "nvarchar":
colInfo.tsType = "string";
break;
case "text":
colInfo.tsType = "string";
break;
case "blob":
colInfo.tsType = "Buffer";
break;
case "clob":
colInfo.tsType = "string";
break;
case "real":
colInfo.tsType = "number";
break;
case "double":
colInfo.tsType = "number";
break;
case "double precision":
colInfo.tsType = "number";
break;
case "float":
colInfo.tsType = "number";
break;
case "numeric":
colInfo.tsType = "number";
break;
case "decimal":
colInfo.tsType = "number";
break;
case "boolean":
colInfo.tsType = "boolean";
break;
case "date":
colInfo.tsType = "string";
break;
case "datetime":
colInfo.tsType = "Date";
break;
default:
TomgUtils.LogError(
`Unknown column type: ${colInfo.options.type} table name: ${ent.tsEntityName} column name: ${resp.name}`
);
break;
}
const options = resp.type.match(/\([0-9 ,]+\)/g);
if (
this.ColumnTypesWithPrecision.some(
v => v === colInfo.options.type
) &&
options
) {
colInfo.options.precision = options[0]
.substring(1, options[0].length - 1)
.split(",")[0] as any;
colInfo.options.scale = options[0]
.substring(1, options[0].length - 1)
.split(",")[1] as any;
}
if (
this.ColumnTypesWithLength.some(
v => v === colInfo.options.type
) &&
options
) {
colInfo.options.length = options[0].substring(
1,
options[0].length - 1
) as any;
}
if (
this.ColumnTypesWithWidth.some(
v =>
v === colInfo.options.type &&
colInfo.tsType !== "boolean"
) &&
options
) {
colInfo.options.width = options[0].substring(
1,
options[0].length - 1
) as any;
}
public async GetCoulmnsFromEntity(entities: Entity[]): Promise<Entity[]> {
throw new Error();
// TODO: Remove
// await Promise.all(
// entities.map(async ent => {
// const response = await this.ExecQuery<{
// cid: number;
// name: string;
// type: string;
// notnull: number;
// dflt_value: string;
// pk: number;
// }>(`PRAGMA table_info('${ent.tsEntityName}');`);
// response.forEach(resp => {
// const colInfo: ColumnInfo = new ColumnInfo();
// colInfo.tsName = resp.name;
// colInfo.options.name = resp.name;
// colInfo.options.nullable = resp.notnull === 0;
// colInfo.options.primary = resp.pk > 0;
// colInfo.options.default = SqliteDriver.ReturnDefaultValueFunction(
// resp.dflt_value
// );
// colInfo.options.type = resp.type
// .replace(/\([0-9 ,]+\)/g, "")
// .toLowerCase()
// .trim() as any;
// colInfo.options.generated =
// colInfo.options.primary &&
// this.tablesWithGeneratedPrimaryKey.includes(
// ent.tsEntityName
// );
// switch (colInfo.options.type) {
// case "int":
// colInfo.tsType = "number";
// break;
// case "integer":
// colInfo.tsType = "number";
// break;
// case "int2":
// colInfo.tsType = "number";
// break;
// case "int8":
// colInfo.tsType = "number";
// break;
// case "tinyint":
// colInfo.tsType = "number";
// break;
// case "smallint":
// colInfo.tsType = "number";
// break;
// case "mediumint":
// colInfo.tsType = "number";
// break;
// case "bigint":
// colInfo.tsType = "string";
// break;
// case "unsigned big int":
// colInfo.tsType = "string";
// break;
// case "character":
// colInfo.tsType = "string";
// break;
// case "varchar":
// colInfo.tsType = "string";
// break;
// case "varying character":
// colInfo.tsType = "string";
// break;
// case "nchar":
// colInfo.tsType = "string";
// break;
// case "native character":
// colInfo.tsType = "string";
// break;
// case "nvarchar":
// colInfo.tsType = "string";
// break;
// case "text":
// colInfo.tsType = "string";
// break;
// case "blob":
// colInfo.tsType = "Buffer";
// break;
// case "clob":
// colInfo.tsType = "string";
// break;
// case "real":
// colInfo.tsType = "number";
// break;
// case "double":
// colInfo.tsType = "number";
// break;
// case "double precision":
// colInfo.tsType = "number";
// break;
// case "float":
// colInfo.tsType = "number";
// break;
// case "numeric":
// colInfo.tsType = "number";
// break;
// case "decimal":
// colInfo.tsType = "number";
// break;
// case "boolean":
// colInfo.tsType = "boolean";
// break;
// case "date":
// colInfo.tsType = "string";
// break;
// case "datetime":
// colInfo.tsType = "Date";
// break;
// default:
// TomgUtils.LogError(
// `Unknown column type: ${colInfo.options.type} table name: ${ent.tsEntityName} column name: ${resp.name}`
// );
// break;
// }
// const options = resp.type.match(/\([0-9 ,]+\)/g);
// if (
// this.ColumnTypesWithPrecision.some(
// v => v === colInfo.options.type
// ) &&
// options
// ) {
// colInfo.options.precision = options[0]
// .substring(1, options[0].length - 1)
// .split(",")[0] as any;
// colInfo.options.scale = options[0]
// .substring(1, options[0].length - 1)
// .split(",")[1] as any;
// }
// if (
// this.ColumnTypesWithLength.some(
// v => v === colInfo.options.type
// ) &&
// options
// ) {
// colInfo.options.length = options[0].substring(
// 1,
// options[0].length - 1
// ) as any;
// }
// if (
// this.ColumnTypesWithWidth.some(
// v =>
// v === colInfo.options.type &&
// colInfo.tsType !== "boolean"
// ) &&
// options
// ) {
// colInfo.options.width = options[0].substring(
// 1,
// options[0].length - 1
// ) as any;
// }
if (colInfo.options.type) {
ent.Columns.push(colInfo);
}
});
})
);
// if (colInfo.options.type) {
// ent.Columns.push(colInfo);
// }
// });
// })
// );
return entities;
// return entities;
}
public async GetIndexesFromEntity(

View File

@ -13,7 +13,7 @@ export type Column = {
width?: number;
nullable?: boolean;
unique?: boolean; // ?
default?: boolean;
default?: string; // ?
precision?: number;
scale?: number;
unsigned?: boolean;

View File

@ -103,12 +103,15 @@ describe("MssqlDriver", function() {
tsType: "number",
relations: [] as RelationInfo[]
});
const result = await driver.GetCoulmnsFromEntity(
entities,
"schema",
"db"
);
expect(result).to.be.deep.equal(expected);
throw new Error();
// TODO: Remove
// const result = await driver.GetCoulmnsFromEntity(
// entities,
// "schema",
// "db"
// );
// expect(result).to.be.deep.equal(expected);
});
it("should find primary indexes");
it("should get indexes info");

View File

@ -80,48 +80,50 @@ function runTestForMultipleDrivers(
it(testName, async function() {
const driversToRun = selectDriversForSpecyficTest();
const modelGenerationPromises = driversToRun.map(async dbDriver => {
const {
generationOptions,
driver,
connectionOptions,
resultsPath,
filesOrgPathTS
} = await prepareTestRuns(testPartialPath, testName, dbDriver);
let dbModel: EntityInfo[] = [];
switch (testName) {
case "144":
dbModel = await dataCollectionPhase(
driver,
Object.assign(connectionOptions, {
databaseName: "db1,db2"
})
);
break;
throw new Error();
// TODO: Remove
// const {
// generationOptions,
// driver,
// connectionOptions,
// resultsPath,
// filesOrgPathTS
// } = await prepareTestRuns(testPartialPath, testName, dbDriver);
// let dbModel: EntityInfo[] = [];
// switch (testName) {
// case "144":
// dbModel = await dataCollectionPhase(
// driver,
// Object.assign(connectionOptions, {
// databaseName: "db1,db2"
// })
// );
// break;
default:
dbModel = await dataCollectionPhase(
driver,
connectionOptions
);
break;
}
// default:
// dbModel = await dataCollectionPhase(
// driver,
// connectionOptions
// );
// break;
// }
dbModel = modelCustomizationPhase(
dbModel,
generationOptions,
driver.defaultValues
);
modelGenerationPhase(connectionOptions, generationOptions, dbModel);
const filesGenPath = path.resolve(resultsPath, "entities");
compareGeneratedFiles(filesOrgPathTS, filesGenPath);
return {
dbModel,
generationOptions,
connectionOptions,
resultsPath,
filesOrgPathTS,
dbDriver
};
// dbModel = modelCustomizationPhase(
// dbModel,
// generationOptions,
// driver.defaultValues
// );
// modelGenerationPhase(connectionOptions, generationOptions, dbModel);
// const filesGenPath = path.resolve(resultsPath, "entities");
// compareGeneratedFiles(filesOrgPathTS, filesGenPath);
// return {
// dbModel,
// generationOptions,
// connectionOptions,
// resultsPath,
// filesOrgPathTS,
// dbDriver
// };
});
await Promise.all(modelGenerationPromises);
compileGeneratedModel(path.resolve(process.cwd(), `output`), dbDrivers);
@ -162,22 +164,24 @@ async function runTest(
filesOrgPathTS
} = await prepareTestRuns(testPartialPath, dbDriver, dbDriver);
let dbModel = await dataCollectionPhase(driver, connectionOptions);
dbModel = modelCustomizationPhase(
dbModel,
generationOptions,
driver.defaultValues
);
modelGenerationPhase(connectionOptions, generationOptions, dbModel);
const filesGenPath = path.resolve(resultsPath, "entities");
compareGeneratedFiles(filesOrgPathTS, filesGenPath);
return {
dbModel,
generationOptions,
connectionOptions,
resultsPath,
filesOrgPathTS,
dbDriver
};
throw new Error();
// TODO: Remove
// dbModel = modelCustomizationPhase(
// dbModel,
// generationOptions,
// driver.defaultValues
// );
// modelGenerationPhase(connectionOptions, generationOptions, dbModel);
// const filesGenPath = path.resolve(resultsPath, "entities");
// compareGeneratedFiles(filesOrgPathTS, filesGenPath);
// return {
// dbModel,
// generationOptions,
// connectionOptions,
// resultsPath,
// filesOrgPathTS,
// dbDriver
// };
});
await Promise.all(modelGenerationPromises);
compileGeneratedModel(path.resolve(process.cwd(), `output`), dbDrivers);