From 5d3dac6be7ccc69d47135025613d5e847aa50f7b Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 17 Dec 2017 11:38:25 +0100 Subject: [PATCH 01/21] adding oracle support - part 1 --- docker-compose.yml | 28 ++- package-lock.json | 14 ++ package.json | 2 + src/drivers/OracleDriver.ts | 471 ++++++++++++++++++++++++++++++++++++ src/index.ts | 9 +- 5 files changed, 513 insertions(+), 11 deletions(-) create mode 100644 src/drivers/OracleDriver.ts diff --git a/docker-compose.yml b/docker-compose.yml index a2b2149..5068342 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,13 +28,23 @@ services: environment: POSTGRES_PASSWORD: "!Passw0rd" - # # mssql - # mssql: - # image: "microsoft/mssql-server-linux:2017-GA" - # container_name: "typeorm-mg-mssql" - # ports: - # - "1433:1433" - # environment: - # ACCEPT_EULA: "Y" - # SA_PASSWORD: "!Passw0rd" + # mssql + mssql: + image: "microsoft/mssql-server-linux:2017-GA" + container_name: "typeorm-mg-mssql" + ports: + - "1433:1433" + environment: + ACCEPT_EULA: "Y" + SA_PASSWORD: "!Passw0rd" + + # oracle + oracle: + image: "store/oracle/database-enterprise:12.2.0.1" + container_name: "typeorm-mg-oracle" + ports: + - "1521:1521" + # environment: + # DB_SID: "ORCLCDB" + # SYS_PASSWORD: "Oradoc_db1" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f324466..0bf8d84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,6 +73,15 @@ "integrity": "sha512-54Dm6NwYeiSQmRB1BLXKr5GELi0wFapR1npi8bnZhEcu84d/yQKqnwwXQ56hZ0RUbTG6L5nqDZaN3dgByQXQRQ==", "dev": true }, + "@types/oracledb": { + "version": "1.11.34", + "resolved": "https://registry.npmjs.org/@types/oracledb/-/oracledb-1.11.34.tgz", + "integrity": "sha512-7cgZaKEfYcPPTScxxCoYoLxmmhM/PBobGBfxE3RGzRJl8YKhkyGKyExFu8fTOpF2cPgdfh83NGKBVX7prWzb+Q==", + "dev": true, + "requires": { + "@types/node": "8.0.53" + } + }, "@types/pg": { "version": "6.1.45", "resolved": "https://registry.npmjs.org/@types/pg/-/pg-6.1.45.tgz", @@ -2443,6 +2452,11 @@ } } }, + "oracledb": { + "version": "2.0.15", + "resolved": "https://registry.npmjs.org/oracledb/-/oracledb-2.0.15.tgz", + "integrity": "sha1-9+IBtp+ngjUIFV6fNKumXVdCbx0=" + }, "os-locale": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", diff --git a/package.json b/package.json index f59778c..2dffad6 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "handlebars": "^4.0.11", "mssql": "^4.0.4", "mysql": "^2.15.0", + "oracledb": "^2.0.15", "pg": "^6.4.2", "reflect-metadata": "^0.1.10", "typeorm": "^0.1.3", @@ -44,6 +45,7 @@ "@types/mssql": "^4.0.4", "@types/mysql": "0.0.34", "@types/node": "^8.0.53", + "@types/oracledb": "^1.11.34", "@types/pg": "^6.1.45", "@types/sinon": "^2.3.7", "chai": "^4.1.2", diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts new file mode 100644 index 0000000..6c4606b --- /dev/null +++ b/src/drivers/OracleDriver.ts @@ -0,0 +1,471 @@ +import { AbstractDriver } from './AbstractDriver' +import * as MSSQL from 'mssql' +import { ColumnInfo } from './../models/ColumnInfo' +import { EntityInfo } from './../models/EntityInfo' +import { RelationInfo } from './../models/RelationInfo' +import { DatabaseModel } from './../models/DatabaseModel' +/** + * OracleDriver + */ +export class OracleDriver extends AbstractDriver { + FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { + dbModel.entities.forEach(entity => { + let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); + if (!primaryIndex) { + console.error(`Table ${entity.EntityName} has no PK.`) + return; + } + entity.Columns.forEach(col => { + if (primaryIndex!.columns.some(cIndex => cIndex.name == col.name)) col.isPrimary = true + }) + }); + } + + async GetAllTables(schema: string): Promise { + let request = new MSSQL.Request(this.Connection) + let response: { TABLE_SCHEMA: string, TABLE_NAME: string }[] + = (await request.query(`SELECT TABLE_SCHEMA,TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA='${schema}'`)).recordset; + let ret: EntityInfo[] = []; + response.forEach((val) => { + let ent: EntityInfo = new EntityInfo(); + ent.EntityName = val.TABLE_NAME; + ent.Columns = []; + ent.Indexes = []; + ret.push(ent); + }) + return ret; + } + async GetCoulmnsFromEntity(entities: EntityInfo[], schema: string): Promise { + let request = new MSSQL.Request(this.Connection) + let 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 + }[] + = (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 FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='${schema}'`)).recordset; + entities.forEach((ent) => { + response.filter((filterVal) => { + return filterVal.TABLE_NAME == ent.EntityName; + }).forEach((resp) => { + let colInfo: ColumnInfo = new ColumnInfo(); + colInfo.name = resp.COLUMN_NAME; + colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false; + colInfo.is_generated = resp.IsIdentity == 1 ? true : false; + colInfo.default = resp.COLUMN_DEFAULT; + switch (resp.DATA_TYPE) { + case "int": + colInfo.ts_type = "number" + colInfo.sql_type = "int" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "tinyint": + colInfo.ts_type = "number" + colInfo.sql_type = "smallint" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "smallint": + colInfo.ts_type = "number" + colInfo.sql_type = "smallint" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "bit": + colInfo.ts_type = "boolean" + colInfo.sql_type = "boolean" + break; + case "float": + colInfo.ts_type = "number" + colInfo.sql_type = "float" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + colInfo.numericPrecision = resp.NUMERIC_PRECISION + break; + case "bigint": + colInfo.ts_type = "string" + colInfo.sql_type = "bigint" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "date": + colInfo.ts_type = "Date" + colInfo.sql_type = "date" + break; + case "time": + colInfo.ts_type = "Date" + colInfo.sql_type = "time" + break; + case "datetime": + colInfo.ts_type = "Date"; + colInfo.sql_type = "datetime" + break; + case "char": + colInfo.ts_type = "string" + colInfo.sql_type = "char" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "nchar": + colInfo.ts_type = "string" + colInfo.sql_type = "nchar" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "text": + colInfo.ts_type = "string" + colInfo.sql_type = "text" + break; + case "ntext": + colInfo.ts_type = "string" + colInfo.sql_type = "ntext" + break; + case "uniqueidentifier": + colInfo.ts_type = "string" + colInfo.sql_type = "uniqueidentifier" + break; + case "varchar": + colInfo.ts_type = "string" + colInfo.sql_type = "varchar" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "binary": + colInfo.ts_type = "Buffer" + colInfo.sql_type = "binary" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "varbinary": + colInfo.ts_type = "Buffer" + colInfo.sql_type = "varbinary" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "image": + colInfo.ts_type = "Buffer" + colInfo.sql_type = "image" + break; + case "nvarchar": + colInfo.ts_type = "string" + colInfo.sql_type = "nvarchar" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "money": + colInfo.ts_type = "number" + colInfo.sql_type = "decimal" + break; + case "smallmoney": + colInfo.ts_type = "number" + colInfo.sql_type = "smallmoney" + break; + case "real": + colInfo.ts_type = "number" + colInfo.sql_type = "double" + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "decimal": + colInfo.ts_type = "number" + colInfo.sql_type = "decimal" + colInfo.numericPrecision = resp.NUMERIC_PRECISION + colInfo.numericScale = resp.NUMERIC_SCALE + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "numeric": + colInfo.ts_type = "number" + colInfo.sql_type = "numeric" + colInfo.numericPrecision = resp.NUMERIC_PRECISION + colInfo.numericScale = resp.NUMERIC_SCALE + colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; + break; + case "datetime2": + colInfo.ts_type = "Date" + colInfo.sql_type = "datetime2" + colInfo.numericPrecision = resp.NUMERIC_PRECISION + break; + case "time": + colInfo.ts_type = "Date" + colInfo.sql_type = "time" + colInfo.numericPrecision = resp.NUMERIC_PRECISION + break; + case "datetimeoffset": + colInfo.ts_type = "Date" + colInfo.sql_type = "datetimeoffset" + colInfo.numericPrecision = resp.NUMERIC_PRECISION + break; + case "smalldatetime": + colInfo.ts_type = "Date" + colInfo.sql_type = "smalldatetime" + break; + case "xml": + colInfo.ts_type = "string" + colInfo.sql_type = "text" + break; + default: + console.error("Unknown column type:" + resp.DATA_TYPE); + break; + } + + if (colInfo.sql_type) ent.Columns.push(colInfo); + }) + }) + return entities; + } + async GetIndexesFromEntity(entities: EntityInfo[], schema: string): Promise { + let request = new MSSQL.Request(this.Connection) + let response: { + TableName: string, IndexName: string, ColumnName: string, is_unique: number, + is_primary_key: number//, is_descending_key: number//, is_included_column: number + }[] + = (await request.query(`SELECT + TableName = t.name, + IndexName = ind.name, + ColumnName = col.name, + ind.is_unique, + ind.is_primary_key + -- ,ic.is_descending_key, + -- ic.is_included_column +FROM + sys.indexes ind +INNER JOIN + sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id +INNER JOIN + sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id +INNER JOIN + sys.tables t ON ind.object_id = t.object_id +INNER JOIN + sys.schemas s on s.schema_id=t.schema_id +WHERE + t.is_ms_shipped = 0 and s.name='${schema}' +ORDER BY + t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset; + entities.forEach((ent) => { + response.filter((filterVal) => { + return filterVal.TableName == ent.EntityName; + }).forEach((resp) => { + let indexInfo: IndexInfo = {}; + let indexColumnInfo: IndexColumnInfo = {}; + if (ent.Indexes.filter((filterVal) => { + return filterVal.name == resp.IndexName + }).length > 0) { + indexInfo = ent.Indexes.filter((filterVal) => { + return filterVal.name == resp.IndexName + })[0]; + } else { + indexInfo.columns = []; + indexInfo.name = resp.IndexName; + indexInfo.isUnique = resp.is_unique == 1 ? true : false; + indexInfo.isPrimaryKey = resp.is_primary_key == 1 ? true : false; + ent.Indexes.push(indexInfo); + } + indexColumnInfo.name = resp.ColumnName; + // indexColumnInfo.isIncludedColumn = resp.is_included_column == 1 ? true : false; + // indexColumnInfo.isDescending = resp.is_descending_key == 1 ? true : false; + indexInfo.columns.push(indexColumnInfo); + + }) + }) + + return entities; + } + async GetRelations(entities: EntityInfo[], schema: string): Promise { + let request = new MSSQL.Request(this.Connection) + let response: { + TableWithForeignKey: string, FK_PartNo: number, ForeignKeyColumn: string, + TableReferenced: string, ForeignKeyColumnReferenced: string, + onDelete: "RESTRICT" | "CASCADE" | "SET NULL", + onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: number + }[] + = (await request.query(`select + parentTable.name as TableWithForeignKey, + fkc.constraint_column_id as FK_PartNo, + parentColumn.name as ForeignKeyColumn, + referencedTable.name as TableReferenced, + referencedColumn.name as ForeignKeyColumnReferenced, + fk.delete_referential_action_desc as onDelete, + fk.update_referential_action_desc as onUpdate, + fk.object_id +from + sys.foreign_keys fk +inner join + sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id +inner join + sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id +inner join + sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id +inner join + sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id +inner join + sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id +inner join + sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id +where + fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name='${schema}' +order by + TableWithForeignKey, FK_PartNo`)).recordset; + let relationsTemp: RelationTempInfo[] = []; + response.forEach((resp) => { + let rels = relationsTemp.find((val) => { + return val.object_id == resp.object_id; + }) + if (rels == undefined) { + rels = {}; + rels.ownerColumnsNames = []; + rels.referencedColumnsNames = []; + rels.actionOnDelete = resp.onDelete; + rels.actionOnUpdate = resp.onUpdate; + rels.object_id = resp.object_id; + rels.ownerTable = resp.TableWithForeignKey; + rels.referencedTable = resp.TableReferenced; + relationsTemp.push(rels); + } + rels.ownerColumnsNames.push(resp.ForeignKeyColumn); + rels.referencedColumnsNames.push(resp.ForeignKeyColumnReferenced); + }) + relationsTemp.forEach((relationTmp) => { + let ownerEntity = entities.find((entitity) => { + return entitity.EntityName == relationTmp.ownerTable; + }) + if (!ownerEntity) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + return; + } + let referencedEntity = entities.find((entitity) => { + return entitity.EntityName == relationTmp.referencedTable; + }) + if (!referencedEntity) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + return; + } + let ownerColumn = ownerEntity.Columns.find((column) => { + return column.name == relationTmp.ownerColumnsNames[0]; + }) + if (!ownerColumn) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + return; + } + let relatedColumn = referencedEntity.Columns.find((column) => { + return column.name == relationTmp.referencedColumnsNames[0]; + }) + if (!relatedColumn) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + return; + } + let ownColumn: ColumnInfo = ownerColumn; + let isOneToMany: boolean; + isOneToMany = false; + let index = ownerEntity.Indexes.find( + (index) => { + return index.isUnique && index.columns.some(col => { + return col.name == ownerColumn!.name + }) + } + ) + if (!index) { + isOneToMany = true; + } else { + isOneToMany = false; + } + let ownerRelation = new RelationInfo() + let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + if (referencedEntity.Columns.filter((filterVal) => { + return filterVal.name == columnName; + }).length>0){ + for (let i=2;i<=ownerEntity.Columns.length;i++){ + columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')+i.toString(); + if (referencedEntity.Columns.filter((filterVal) => { + return filterVal.name == columnName; + }).length==0) break; + } + } + ownerRelation.actionOnDelete = relationTmp.actionOnDelete + ownerRelation.actionOnUpdate = relationTmp.actionOnUpdate + ownerRelation.isOwner = true + ownerRelation.relatedColumn = relatedColumn.name.toLowerCase() + ownerRelation.relatedTable = relationTmp.referencedTable + ownerRelation.ownerTable = relationTmp.ownerTable + ownerRelation.ownerColumn = columnName + ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne" + ownerColumn.relations.push(ownerRelation) + if (isOneToMany) { + let col = new ColumnInfo() + col.name = columnName + let referencedRelation = new RelationInfo(); + col.relations.push(referencedRelation) + referencedRelation.actionOnDelete = relationTmp.actionOnDelete + referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate + referencedRelation.isOwner = false + referencedRelation.relatedColumn = ownerColumn.name + referencedRelation.relatedTable = relationTmp.ownerTable + referencedRelation.ownerTable = relationTmp.referencedTable + referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() + referencedRelation.relationType = "OneToMany" + referencedEntity.Columns.push(col) + } else { + let col = new ColumnInfo() + col.name = columnName + let referencedRelation = new RelationInfo(); + col.relations.push(referencedRelation) + referencedRelation.actionOnDelete = relationTmp.actionOnDelete + referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate + referencedRelation.isOwner = false + referencedRelation.relatedColumn = ownerColumn.name + referencedRelation.relatedTable = relationTmp.ownerTable + referencedRelation.ownerTable = relationTmp.referencedTable + referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() + referencedRelation.relationType = "OneToOne" + + referencedEntity.Columns.push(col) + } + }) + return entities; + } + async DisconnectFromServer() { + if (this.Connection) + await this.Connection.close(); + } + + private Connection: MSSQL.ConnectionPool; + async ConnectToServer(database: string, server: string, port: number, user: string, password: string, ssl: boolean) { + let config: MSSQL.config = { + database: database, + server: server, + port: port, + user: user, + password: password, + options: { + encrypt: ssl, // Use this if you're on Windows Azure + appName: 'typeorm-model-generator' + } + } + + + let promise = new Promise( + (resolve, reject) => { + this.Connection = new MSSQL.ConnectionPool(config, (err) => { + if (!err) { + //Connection successfull + resolve(true) + } + else { + console.error('Error connecting to MSSQL Server.') + console.error(err.message) + process.abort() + reject(err) + } + }); + } + ) + + await promise; + } + async CreateDB(dbName: string) { + let request = new MSSQL.Request(this.Connection); + let resp = await request.query(`CREATE DATABASE ${dbName}; `) + } + async UseDB(dbName: string) { + let request = new MSSQL.Request(this.Connection); + let resp = await request.query(`USE ${dbName}; `) + } + async DropDB(dbName: string) { + let request = new MSSQL.Request(this.Connection); + let resp = await request.query(`DROP DATABASE ${dbName}; `) + } + async CheckIfDBExists(dbName: string): Promise { + let request = new MSSQL.Request(this.Connection); + let resp = await request.query(`SELECT name FROM master.sys.databases WHERE name = N'${dbName}' `) + return resp.recordset.length > 0; + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index e0f9090..5e3638b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { MssqlDriver } from './drivers/MssqlDriver'; import { PostgresDriver } from "./drivers/PostgresDriver"; import { MysqlDriver } from "./drivers/MysqlDriver"; import { MariaDbDriver } from "./drivers/MariaDbDriver"; +import { OracleDriver } from "./drivers/OracleDriver"; import { Engine } from './Engine' import * as Yargs from 'yargs' import path = require('path') @@ -38,7 +39,7 @@ var argv = Yargs .option('e', { alias: 'engine', describe: 'Database engine.', - choices: ['mssql', 'postgres', 'mysql', 'mariadb'], + choices: ['mssql', 'postgres', 'mysql', 'mariadb','oracle'], default: 'mssql' }) .option('o', { @@ -75,10 +76,14 @@ switch (argv.e) { driver = new MysqlDriver(); standardPort = 3306; break; - case 'mariadb': + case 'mariadb': driver = new MysqlDriver(); standardPort = 3306; break; + case 'oracle': + driver = new OracleDriver(); + standardPort = 1521; + break; default: console.error('Database engine not recognized.') process.abort(); From 49a11b5ec9e950b3588fa0cc6698992556f3d56c Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 18 Dec 2017 22:34:31 +0100 Subject: [PATCH 02/21] oracle - getting all tables --- docker-compose.yml | 2 +- src/drivers/OracleDriver.ts | 811 ++++++++++++++------------- test/integration/integration.test.ts | 6 +- test/utils/GeneralTestUtils.ts | 46 ++ 4 files changed, 464 insertions(+), 401 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5068342..645b9c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,7 @@ services: # oracle oracle: - image: "store/oracle/database-enterprise:12.2.0.1" + image: "store/oracle/database-enterprise:12.2.0.1-slim" container_name: "typeorm-mg-oracle" ports: - "1521:1521" diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 6c4606b..12f8e67 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -1,9 +1,10 @@ import { AbstractDriver } from './AbstractDriver' -import * as MSSQL from 'mssql' +import * as Oracle from 'oracledb' import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' +import {promisify} from 'util' /** * OracleDriver */ @@ -20,15 +21,17 @@ export class OracleDriver extends AbstractDriver { }) }); } + + + async GetAllTables(schema: string): Promise { - let request = new MSSQL.Request(this.Connection) - let response: { TABLE_SCHEMA: string, TABLE_NAME: string }[] - = (await request.query(`SELECT TABLE_SCHEMA,TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA='${schema}'`)).recordset; + + let response :any[][] = ( await this.Connection.execute(` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`)).rows!; let ret: EntityInfo[] = []; response.forEach((val) => { let ent: EntityInfo = new EntityInfo(); - ent.EntityName = val.TABLE_NAME; + ent.EntityName = val[0]; ent.Columns = []; ent.Indexes = []; ret.push(ent); @@ -36,380 +39,380 @@ export class OracleDriver extends AbstractDriver { return ret; } async GetCoulmnsFromEntity(entities: EntityInfo[], schema: string): Promise { - let request = new MSSQL.Request(this.Connection) - let 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 - }[] - = (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 FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='${schema}'`)).recordset; - entities.forEach((ent) => { - response.filter((filterVal) => { - return filterVal.TABLE_NAME == ent.EntityName; - }).forEach((resp) => { - let colInfo: ColumnInfo = new ColumnInfo(); - colInfo.name = resp.COLUMN_NAME; - colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false; - colInfo.is_generated = resp.IsIdentity == 1 ? true : false; - colInfo.default = resp.COLUMN_DEFAULT; - switch (resp.DATA_TYPE) { - case "int": - colInfo.ts_type = "number" - colInfo.sql_type = "int" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "tinyint": - colInfo.ts_type = "number" - colInfo.sql_type = "smallint" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "smallint": - colInfo.ts_type = "number" - colInfo.sql_type = "smallint" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "bit": - colInfo.ts_type = "boolean" - colInfo.sql_type = "boolean" - break; - case "float": - colInfo.ts_type = "number" - colInfo.sql_type = "float" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - colInfo.numericPrecision = resp.NUMERIC_PRECISION - break; - case "bigint": - colInfo.ts_type = "string" - colInfo.sql_type = "bigint" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "date": - colInfo.ts_type = "Date" - colInfo.sql_type = "date" - break; - case "time": - colInfo.ts_type = "Date" - colInfo.sql_type = "time" - break; - case "datetime": - colInfo.ts_type = "Date"; - colInfo.sql_type = "datetime" - break; - case "char": - colInfo.ts_type = "string" - colInfo.sql_type = "char" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "nchar": - colInfo.ts_type = "string" - colInfo.sql_type = "nchar" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "text": - colInfo.ts_type = "string" - colInfo.sql_type = "text" - break; - case "ntext": - colInfo.ts_type = "string" - colInfo.sql_type = "ntext" - break; - case "uniqueidentifier": - colInfo.ts_type = "string" - colInfo.sql_type = "uniqueidentifier" - break; - case "varchar": - colInfo.ts_type = "string" - colInfo.sql_type = "varchar" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "binary": - colInfo.ts_type = "Buffer" - colInfo.sql_type = "binary" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "varbinary": - colInfo.ts_type = "Buffer" - colInfo.sql_type = "varbinary" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "image": - colInfo.ts_type = "Buffer" - colInfo.sql_type = "image" - break; - case "nvarchar": - colInfo.ts_type = "string" - colInfo.sql_type = "nvarchar" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "money": - colInfo.ts_type = "number" - colInfo.sql_type = "decimal" - break; - case "smallmoney": - colInfo.ts_type = "number" - colInfo.sql_type = "smallmoney" - break; - case "real": - colInfo.ts_type = "number" - colInfo.sql_type = "double" - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "decimal": - colInfo.ts_type = "number" - colInfo.sql_type = "decimal" - colInfo.numericPrecision = resp.NUMERIC_PRECISION - colInfo.numericScale = resp.NUMERIC_SCALE - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "numeric": - colInfo.ts_type = "number" - colInfo.sql_type = "numeric" - colInfo.numericPrecision = resp.NUMERIC_PRECISION - colInfo.numericScale = resp.NUMERIC_SCALE - colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; - break; - case "datetime2": - colInfo.ts_type = "Date" - colInfo.sql_type = "datetime2" - colInfo.numericPrecision = resp.NUMERIC_PRECISION - break; - case "time": - colInfo.ts_type = "Date" - colInfo.sql_type = "time" - colInfo.numericPrecision = resp.NUMERIC_PRECISION - break; - case "datetimeoffset": - colInfo.ts_type = "Date" - colInfo.sql_type = "datetimeoffset" - colInfo.numericPrecision = resp.NUMERIC_PRECISION - break; - case "smalldatetime": - colInfo.ts_type = "Date" - colInfo.sql_type = "smalldatetime" - break; - case "xml": - colInfo.ts_type = "string" - colInfo.sql_type = "text" - break; - default: - console.error("Unknown column type:" + resp.DATA_TYPE); - break; - } +// let request = new Oracle.Request(this.Connection) +// let 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 +// }[] +// = (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 FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='${schema}'`)).recordset; +// entities.forEach((ent) => { +// response.filter((filterVal) => { +// return filterVal.TABLE_NAME == ent.EntityName; +// }).forEach((resp) => { +// let colInfo: ColumnInfo = new ColumnInfo(); +// colInfo.name = resp.COLUMN_NAME; +// colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false; +// colInfo.is_generated = resp.IsIdentity == 1 ? true : false; +// colInfo.default = resp.COLUMN_DEFAULT; +// switch (resp.DATA_TYPE) { +// case "int": +// colInfo.ts_type = "number" +// colInfo.sql_type = "int" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "tinyint": +// colInfo.ts_type = "number" +// colInfo.sql_type = "smallint" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "smallint": +// colInfo.ts_type = "number" +// colInfo.sql_type = "smallint" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "bit": +// colInfo.ts_type = "boolean" +// colInfo.sql_type = "boolean" +// break; +// case "float": +// colInfo.ts_type = "number" +// colInfo.sql_type = "float" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// break; +// case "bigint": +// colInfo.ts_type = "string" +// colInfo.sql_type = "bigint" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "date": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "date" +// break; +// case "time": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "time" +// break; +// case "datetime": +// colInfo.ts_type = "Date"; +// colInfo.sql_type = "datetime" +// break; +// case "char": +// colInfo.ts_type = "string" +// colInfo.sql_type = "char" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "nchar": +// colInfo.ts_type = "string" +// colInfo.sql_type = "nchar" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "text": +// colInfo.ts_type = "string" +// colInfo.sql_type = "text" +// break; +// case "ntext": +// colInfo.ts_type = "string" +// colInfo.sql_type = "ntext" +// break; +// case "uniqueidentifier": +// colInfo.ts_type = "string" +// colInfo.sql_type = "uniqueidentifier" +// break; +// case "varchar": +// colInfo.ts_type = "string" +// colInfo.sql_type = "varchar" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "binary": +// colInfo.ts_type = "Buffer" +// colInfo.sql_type = "binary" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "varbinary": +// colInfo.ts_type = "Buffer" +// colInfo.sql_type = "varbinary" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "image": +// colInfo.ts_type = "Buffer" +// colInfo.sql_type = "image" +// break; +// case "nvarchar": +// colInfo.ts_type = "string" +// colInfo.sql_type = "nvarchar" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "money": +// colInfo.ts_type = "number" +// colInfo.sql_type = "decimal" +// break; +// case "smallmoney": +// colInfo.ts_type = "number" +// colInfo.sql_type = "smallmoney" +// break; +// case "real": +// colInfo.ts_type = "number" +// colInfo.sql_type = "double" +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "decimal": +// colInfo.ts_type = "number" +// colInfo.sql_type = "decimal" +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// colInfo.numericScale = resp.NUMERIC_SCALE +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "numeric": +// colInfo.ts_type = "number" +// colInfo.sql_type = "numeric" +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// colInfo.numericScale = resp.NUMERIC_SCALE +// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; +// break; +// case "datetime2": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "datetime2" +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// break; +// case "time": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "time" +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// break; +// case "datetimeoffset": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "datetimeoffset" +// colInfo.numericPrecision = resp.NUMERIC_PRECISION +// break; +// case "smalldatetime": +// colInfo.ts_type = "Date" +// colInfo.sql_type = "smalldatetime" +// break; +// case "xml": +// colInfo.ts_type = "string" +// colInfo.sql_type = "text" +// break; +// default: +// console.error("Unknown column type:" + resp.DATA_TYPE); +// break; +// } - if (colInfo.sql_type) ent.Columns.push(colInfo); - }) - }) +// if (colInfo.sql_type) ent.Columns.push(colInfo); +// }) +// }) return entities; } async GetIndexesFromEntity(entities: EntityInfo[], schema: string): Promise { - let request = new MSSQL.Request(this.Connection) - let response: { - TableName: string, IndexName: string, ColumnName: string, is_unique: number, - is_primary_key: number//, is_descending_key: number//, is_included_column: number - }[] - = (await request.query(`SELECT - TableName = t.name, - IndexName = ind.name, - ColumnName = col.name, - ind.is_unique, - ind.is_primary_key - -- ,ic.is_descending_key, - -- ic.is_included_column -FROM - sys.indexes ind -INNER JOIN - sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id -INNER JOIN - sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id -INNER JOIN - sys.tables t ON ind.object_id = t.object_id -INNER JOIN - sys.schemas s on s.schema_id=t.schema_id -WHERE - t.is_ms_shipped = 0 and s.name='${schema}' -ORDER BY - t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset; - entities.forEach((ent) => { - response.filter((filterVal) => { - return filterVal.TableName == ent.EntityName; - }).forEach((resp) => { - let indexInfo: IndexInfo = {}; - let indexColumnInfo: IndexColumnInfo = {}; - if (ent.Indexes.filter((filterVal) => { - return filterVal.name == resp.IndexName - }).length > 0) { - indexInfo = ent.Indexes.filter((filterVal) => { - return filterVal.name == resp.IndexName - })[0]; - } else { - indexInfo.columns = []; - indexInfo.name = resp.IndexName; - indexInfo.isUnique = resp.is_unique == 1 ? true : false; - indexInfo.isPrimaryKey = resp.is_primary_key == 1 ? true : false; - ent.Indexes.push(indexInfo); - } - indexColumnInfo.name = resp.ColumnName; - // indexColumnInfo.isIncludedColumn = resp.is_included_column == 1 ? true : false; - // indexColumnInfo.isDescending = resp.is_descending_key == 1 ? true : false; - indexInfo.columns.push(indexColumnInfo); +// let request = new Oracle.Request(this.Connection) +// let response: { +// TableName: string, IndexName: string, ColumnName: string, is_unique: number, +// is_primary_key: number//, is_descending_key: number//, is_included_column: number +// }[] +// = (await request.query(`SELECT +// TableName = t.name, +// IndexName = ind.name, +// ColumnName = col.name, +// ind.is_unique, +// ind.is_primary_key +// -- ,ic.is_descending_key, +// -- ic.is_included_column +// FROM +// sys.indexes ind +// INNER JOIN +// sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id +// INNER JOIN +// sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id +// INNER JOIN +// sys.tables t ON ind.object_id = t.object_id +// INNER JOIN +// sys.schemas s on s.schema_id=t.schema_id +// WHERE +// t.is_ms_shipped = 0 and s.name='${schema}' +// ORDER BY +// t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset; +// entities.forEach((ent) => { +// response.filter((filterVal) => { +// return filterVal.TableName == ent.EntityName; +// }).forEach((resp) => { +// let indexInfo: IndexInfo = {}; +// let indexColumnInfo: IndexColumnInfo = {}; +// if (ent.Indexes.filter((filterVal) => { +// return filterVal.name == resp.IndexName +// }).length > 0) { +// indexInfo = ent.Indexes.filter((filterVal) => { +// return filterVal.name == resp.IndexName +// })[0]; +// } else { +// indexInfo.columns = []; +// indexInfo.name = resp.IndexName; +// indexInfo.isUnique = resp.is_unique == 1 ? true : false; +// indexInfo.isPrimaryKey = resp.is_primary_key == 1 ? true : false; +// ent.Indexes.push(indexInfo); +// } +// indexColumnInfo.name = resp.ColumnName; +// // indexColumnInfo.isIncludedColumn = resp.is_included_column == 1 ? true : false; +// // indexColumnInfo.isDescending = resp.is_descending_key == 1 ? true : false; +// indexInfo.columns.push(indexColumnInfo); - }) - }) +// }) +// }) return entities; } async GetRelations(entities: EntityInfo[], schema: string): Promise { - let request = new MSSQL.Request(this.Connection) - let response: { - TableWithForeignKey: string, FK_PartNo: number, ForeignKeyColumn: string, - TableReferenced: string, ForeignKeyColumnReferenced: string, - onDelete: "RESTRICT" | "CASCADE" | "SET NULL", - onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: number - }[] - = (await request.query(`select - parentTable.name as TableWithForeignKey, - fkc.constraint_column_id as FK_PartNo, - parentColumn.name as ForeignKeyColumn, - referencedTable.name as TableReferenced, - referencedColumn.name as ForeignKeyColumnReferenced, - fk.delete_referential_action_desc as onDelete, - fk.update_referential_action_desc as onUpdate, - fk.object_id -from - sys.foreign_keys fk -inner join - sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id -inner join - sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id -inner join - sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id -inner join - sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id -inner join - sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id -inner join - sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id -where - fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name='${schema}' -order by - TableWithForeignKey, FK_PartNo`)).recordset; - let relationsTemp: RelationTempInfo[] = []; - response.forEach((resp) => { - let rels = relationsTemp.find((val) => { - return val.object_id == resp.object_id; - }) - if (rels == undefined) { - rels = {}; - rels.ownerColumnsNames = []; - rels.referencedColumnsNames = []; - rels.actionOnDelete = resp.onDelete; - rels.actionOnUpdate = resp.onUpdate; - rels.object_id = resp.object_id; - rels.ownerTable = resp.TableWithForeignKey; - rels.referencedTable = resp.TableReferenced; - relationsTemp.push(rels); - } - rels.ownerColumnsNames.push(resp.ForeignKeyColumn); - rels.referencedColumnsNames.push(resp.ForeignKeyColumnReferenced); - }) - relationsTemp.forEach((relationTmp) => { - let ownerEntity = entities.find((entitity) => { - return entitity.EntityName == relationTmp.ownerTable; - }) - if (!ownerEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) - return; - } - let referencedEntity = entities.find((entitity) => { - return entitity.EntityName == relationTmp.referencedTable; - }) - if (!referencedEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) - return; - } - let ownerColumn = ownerEntity.Columns.find((column) => { - return column.name == relationTmp.ownerColumnsNames[0]; - }) - if (!ownerColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) - return; - } - let relatedColumn = referencedEntity.Columns.find((column) => { - return column.name == relationTmp.referencedColumnsNames[0]; - }) - if (!relatedColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) - return; - } - let ownColumn: ColumnInfo = ownerColumn; - let isOneToMany: boolean; - isOneToMany = false; - let index = ownerEntity.Indexes.find( - (index) => { - return index.isUnique && index.columns.some(col => { - return col.name == ownerColumn!.name - }) - } - ) - if (!index) { - isOneToMany = true; - } else { - isOneToMany = false; - } - let ownerRelation = new RelationInfo() - let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') - if (referencedEntity.Columns.filter((filterVal) => { - return filterVal.name == columnName; - }).length>0){ - for (let i=2;i<=ownerEntity.Columns.length;i++){ - columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')+i.toString(); - if (referencedEntity.Columns.filter((filterVal) => { - return filterVal.name == columnName; - }).length==0) break; - } - } - ownerRelation.actionOnDelete = relationTmp.actionOnDelete - ownerRelation.actionOnUpdate = relationTmp.actionOnUpdate - ownerRelation.isOwner = true - ownerRelation.relatedColumn = relatedColumn.name.toLowerCase() - ownerRelation.relatedTable = relationTmp.referencedTable - ownerRelation.ownerTable = relationTmp.ownerTable - ownerRelation.ownerColumn = columnName - ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne" - ownerColumn.relations.push(ownerRelation) - if (isOneToMany) { - let col = new ColumnInfo() - col.name = columnName - let referencedRelation = new RelationInfo(); - col.relations.push(referencedRelation) - referencedRelation.actionOnDelete = relationTmp.actionOnDelete - referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate - referencedRelation.isOwner = false - referencedRelation.relatedColumn = ownerColumn.name - referencedRelation.relatedTable = relationTmp.ownerTable - referencedRelation.ownerTable = relationTmp.referencedTable - referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() - referencedRelation.relationType = "OneToMany" - referencedEntity.Columns.push(col) - } else { - let col = new ColumnInfo() - col.name = columnName - let referencedRelation = new RelationInfo(); - col.relations.push(referencedRelation) - referencedRelation.actionOnDelete = relationTmp.actionOnDelete - referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate - referencedRelation.isOwner = false - referencedRelation.relatedColumn = ownerColumn.name - referencedRelation.relatedTable = relationTmp.ownerTable - referencedRelation.ownerTable = relationTmp.referencedTable - referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() - referencedRelation.relationType = "OneToOne" +// let request = new Oracle.Request(this.Connection) +// let response: { +// TableWithForeignKey: string, FK_PartNo: number, ForeignKeyColumn: string, +// TableReferenced: string, ForeignKeyColumnReferenced: string, +// onDelete: "RESTRICT" | "CASCADE" | "SET NULL", +// onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: number +// }[] +// = (await request.query(`select +// parentTable.name as TableWithForeignKey, +// fkc.constraint_column_id as FK_PartNo, +// parentColumn.name as ForeignKeyColumn, +// referencedTable.name as TableReferenced, +// referencedColumn.name as ForeignKeyColumnReferenced, +// fk.delete_referential_action_desc as onDelete, +// fk.update_referential_action_desc as onUpdate, +// fk.object_id +// from +// sys.foreign_keys fk +// inner join +// sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id +// inner join +// sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id +// inner join +// sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id +// inner join +// sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id +// inner join +// sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id +// inner join +// sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id +// where +// fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name='${schema}' +// order by +// TableWithForeignKey, FK_PartNo`)).recordset; +// let relationsTemp: RelationTempInfo[] = []; +// response.forEach((resp) => { +// let rels = relationsTemp.find((val) => { +// return val.object_id == resp.object_id; +// }) +// if (rels == undefined) { +// rels = {}; +// rels.ownerColumnsNames = []; +// rels.referencedColumnsNames = []; +// rels.actionOnDelete = resp.onDelete; +// rels.actionOnUpdate = resp.onUpdate; +// rels.object_id = resp.object_id; +// rels.ownerTable = resp.TableWithForeignKey; +// rels.referencedTable = resp.TableReferenced; +// relationsTemp.push(rels); +// } +// rels.ownerColumnsNames.push(resp.ForeignKeyColumn); +// rels.referencedColumnsNames.push(resp.ForeignKeyColumnReferenced); +// }) +// relationsTemp.forEach((relationTmp) => { +// let ownerEntity = entities.find((entitity) => { +// return entitity.EntityName == relationTmp.ownerTable; +// }) +// if (!ownerEntity) { +// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) +// return; +// } +// let referencedEntity = entities.find((entitity) => { +// return entitity.EntityName == relationTmp.referencedTable; +// }) +// if (!referencedEntity) { +// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) +// return; +// } +// let ownerColumn = ownerEntity.Columns.find((column) => { +// return column.name == relationTmp.ownerColumnsNames[0]; +// }) +// if (!ownerColumn) { +// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) +// return; +// } +// let relatedColumn = referencedEntity.Columns.find((column) => { +// return column.name == relationTmp.referencedColumnsNames[0]; +// }) +// if (!relatedColumn) { +// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) +// return; +// } +// let ownColumn: ColumnInfo = ownerColumn; +// let isOneToMany: boolean; +// isOneToMany = false; +// let index = ownerEntity.Indexes.find( +// (index) => { +// return index.isUnique && index.columns.some(col => { +// return col.name == ownerColumn!.name +// }) +// } +// ) +// if (!index) { +// isOneToMany = true; +// } else { +// isOneToMany = false; +// } +// let ownerRelation = new RelationInfo() +// let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') +// if (referencedEntity.Columns.filter((filterVal) => { +// return filterVal.name == columnName; +// }).length > 0) { +// for (let i = 2; i <= ownerEntity.Columns.length; i++) { +// columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); +// if (referencedEntity.Columns.filter((filterVal) => { +// return filterVal.name == columnName; +// }).length == 0) break; +// } +// } +// ownerRelation.actionOnDelete = relationTmp.actionOnDelete +// ownerRelation.actionOnUpdate = relationTmp.actionOnUpdate +// ownerRelation.isOwner = true +// ownerRelation.relatedColumn = relatedColumn.name.toLowerCase() +// ownerRelation.relatedTable = relationTmp.referencedTable +// ownerRelation.ownerTable = relationTmp.ownerTable +// ownerRelation.ownerColumn = columnName +// ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne" +// ownerColumn.relations.push(ownerRelation) +// if (isOneToMany) { +// let col = new ColumnInfo() +// col.name = columnName +// let referencedRelation = new RelationInfo(); +// col.relations.push(referencedRelation) +// referencedRelation.actionOnDelete = relationTmp.actionOnDelete +// referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate +// referencedRelation.isOwner = false +// referencedRelation.relatedColumn = ownerColumn.name +// referencedRelation.relatedTable = relationTmp.ownerTable +// referencedRelation.ownerTable = relationTmp.referencedTable +// referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() +// referencedRelation.relationType = "OneToMany" +// referencedEntity.Columns.push(col) +// } else { +// let col = new ColumnInfo() +// col.name = columnName +// let referencedRelation = new RelationInfo(); +// col.relations.push(referencedRelation) +// referencedRelation.actionOnDelete = relationTmp.actionOnDelete +// referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate +// referencedRelation.isOwner = false +// referencedRelation.relatedColumn = ownerColumn.name +// referencedRelation.relatedTable = relationTmp.ownerTable +// referencedRelation.ownerTable = relationTmp.referencedTable +// referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() +// referencedRelation.relationType = "OneToOne" - referencedEntity.Columns.push(col) - } - }) +// referencedEntity.Columns.push(col) +// } +// }) return entities; } async DisconnectFromServer() { @@ -417,55 +420,65 @@ order by await this.Connection.close(); } - private Connection: MSSQL.ConnectionPool; + private Connection: Oracle.IConnection; async ConnectToServer(database: string, server: string, port: number, user: string, password: string, ssl: boolean) { - let config: MSSQL.config = { - database: database, - server: server, - port: port, + let config: Oracle.IConnectionAttributes = { user: user, password: password, - options: { - encrypt: ssl, // Use this if you're on Windows Azure - appName: 'typeorm-model-generator' - } + // connectString: `${server}:${port}/ORCLCDB.localdomain/${database}`, + connectString: `${server}:${port}/${database}`, + externalAuth: ssl } + let that=this; let promise = new Promise( (resolve, reject) => { - this.Connection = new MSSQL.ConnectionPool(config, (err) => { - if (!err) { - //Connection successfull - resolve(true) - } - else { - console.error('Error connecting to MSSQL Server.') - console.error(err.message) - process.abort() - reject(err) - } - }); + Oracle.getConnection( + config, + function (err, connection) { + if (!err) { + //Connection successfull + that.Connection=connection + resolve(true) + } + else { + console.error('Error connecting to Oracle Server.') + console.error(err.message) + process.abort() + reject(err) + } + + }); } ) await promise; } + // connection.execute( + // `SELECT department_id, department_name + // FROM departments + // WHERE manager_id < :id`, + // [110], // bind value for :id + // function(err, result) + // { + // if (err) { + // console.error(err.message); + // doRelease(connection); + // return; + // } + // console.log(result.rows); + // doRelease(connection); + // }); + + async CreateDB(dbName: string) { - let request = new MSSQL.Request(this.Connection); - let resp = await request.query(`CREATE DATABASE ${dbName}; `) } async UseDB(dbName: string) { - let request = new MSSQL.Request(this.Connection); - let resp = await request.query(`USE ${dbName}; `) } async DropDB(dbName: string) { - let request = new MSSQL.Request(this.Connection); - let resp = await request.query(`DROP DATABASE ${dbName}; `) } async CheckIfDBExists(dbName: string): Promise { - let request = new MSSQL.Request(this.Connection); - let resp = await request.query(`SELECT name FROM master.sys.databases WHERE name = N'${dbName}' `) - return resp.recordset.length > 0; + return true; } } \ No newline at end of file diff --git a/test/integration/integration.test.ts b/test/integration/integration.test.ts index 1a9395d..fe0619b 100644 --- a/test/integration/integration.test.ts +++ b/test/integration/integration.test.ts @@ -25,6 +25,7 @@ describe("TypeOrm examples", async function () { if (process.env.MYSQL_Skip == '0') dbDrivers.push('mysql') if (process.env.MARIADB_Skip == '0') dbDrivers.push('mariadb') if (process.env.MSSQL_Skip == '0') dbDrivers.push('mssql') + if (process.env.Oracle_Skip == '0') dbDrivers.push('oracle') let examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/examples') let examplesPathTS = path.resolve(process.cwd(), 'test/integration/examples') @@ -52,9 +53,12 @@ describe("TypeOrm examples", async function () { case 'mysql': engine = await GTU.createMysqlModels(filesOrgPathJS, resultsPath) break; - case 'mariadb': + case 'mariadb': engine = await GTU.createMariaDBModels(filesOrgPathJS, resultsPath) break; + case 'oracle': + engine = await GTU.createOracleDBModels(filesOrgPathJS, resultsPath) + break; default: console.log(`Unknown engine type`); diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 5226f77..3b6a5be 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -4,6 +4,7 @@ import { MssqlDriver } from "../../src/drivers/MssqlDriver"; import { PostgresDriver } from "./../../src/drivers/PostgresDriver"; import { MysqlDriver } from "../../src/drivers/MysqlDriver"; import { MariaDbDriver } from "../../src/drivers/MariaDbDriver"; +import { OracleDriver } from "../../src/drivers/OracleDriver"; import { Engine } from "../../src/Engine"; import { createConnection, ConnectionOptions, Connection } from "typeorm"; import * as yn from "yn" @@ -184,6 +185,51 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str + return engine; +} + +export async function createOracleDBModels(filesOrgPath: string, resultsPath: string): Promise { + let driver: AbstractDriver; + driver = new OracleDriver(); + await driver.ConnectToServer(`mysql`, String(process.env.ORACLE_Host), Number(process.env.ORACLE_Port), String(process.env.ORACLE_Username), String(process.env.ORACLE_Password), yn(process.env.ORACLE_SSL)); + + if (! await driver.CheckIfDBExists(String(process.env.ORACLE_Database))) + await driver.CreateDB(String(process.env.ORACLE_Database)); + await driver.DisconnectFromServer(); + + let connOpt: ConnectionOptions = { + + database: String(process.env.ORACLE_Database), + host: String(process.env.ORACLE_Host), + password: String(process.env.ORACLE_Password), + type: 'oracle', + username: String(process.env.ORACLE_Username), + port: Number(process.env.ORACLE_Port), + dropSchema: true, + synchronize: true, + entities: [path.resolve(filesOrgPath, '*.js')], + } + let conn = await createConnection(connOpt) + + if (conn.isConnected) + await conn.close() + + driver = new OracleDriver(); + let engine = new Engine( + driver, { + host: String(process.env.ORACLE_Host), + port: Number(process.env.ORACLE_Port), + databaseName: String(process.env.ORACLE_Database), + user: String(process.env.ORACLE_Username), + password: String(process.env.ORACLE_Password), + databaseType: 'oracle', + resultsPath: resultsPath, + schemaName: String(process.env.ORACLE_Username), + ssl: yn(process.env.ORACLE_SSL) + }); + + + return engine; } From f901979ecb9caa5d138d842d72d6119f73abf74a Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 19 Dec 2017 23:01:16 +0100 Subject: [PATCH 03/21] oracle - changes in travis - docker login --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c34cc42..50c02fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,12 @@ services: - docker env: - - POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=postgres POSTGRES_Password=!Passw0rd POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=!Passw0rd MYSQL_Database=typeorm_mg MYSQL_SSL=1 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 MARIADB_Username=root MARIADB_Password=!Passw0rd MARIADB_Database=typeorm_mg MARIADB_SSL=0 + - POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=postgres POSTGRES_Password=!Passw0rd POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=!Passw0rd MYSQL_Database=typeorm_mg MYSQL_SSL=1 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 MARIADB_Username=root MARIADB_Password=!Passw0rd MARIADB_Database=typeorm_mg MARIADB_SSL=0 ORACLE_Skip=0 ORACLE_Host=localhost ORACLE_Port=1521 ORACLE_Username=system ORACLE_Password=Oradoc_db1 ORACLE_Database=ORCLCDB ORACLE_SSL=0 before_install: - sudo service mysql stop - sudo service postgresql stop + - docker login - docker-compose up -d From 957cf0df29b03e81cc60c3552f6cd36f00d87bf0 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 19 Dec 2017 23:04:38 +0100 Subject: [PATCH 04/21] docker login - fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 50c02fa..5ec5dc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: before_install: - sudo service mysql stop - sudo service postgresql stop - - docker login + - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - docker-compose up -d From 7f2d577b5e02c0449e2d69e71b815fc48848d7c4 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 24 Dec 2017 00:58:10 +0100 Subject: [PATCH 05/21] oracle - all sql queries, no defined column types, changes needed in connection string generating --- src/drivers/OracleDriver.ts | 568 +++++++++++---------------------- test/utils/GeneralTestUtils.ts | 2 +- 2 files changed, 189 insertions(+), 381 deletions(-) diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 12f8e67..7d4eb6c 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -39,380 +39,203 @@ export class OracleDriver extends AbstractDriver { return ret; } async GetCoulmnsFromEntity(entities: EntityInfo[], schema: string): Promise { -// let request = new Oracle.Request(this.Connection) -// let 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 -// }[] -// = (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 FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='${schema}'`)).recordset; -// entities.forEach((ent) => { -// response.filter((filterVal) => { -// return filterVal.TABLE_NAME == ent.EntityName; -// }).forEach((resp) => { -// let colInfo: ColumnInfo = new ColumnInfo(); -// colInfo.name = resp.COLUMN_NAME; -// colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false; -// colInfo.is_generated = resp.IsIdentity == 1 ? true : false; -// colInfo.default = resp.COLUMN_DEFAULT; -// switch (resp.DATA_TYPE) { -// case "int": -// colInfo.ts_type = "number" -// colInfo.sql_type = "int" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "tinyint": -// colInfo.ts_type = "number" -// colInfo.sql_type = "smallint" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "smallint": -// colInfo.ts_type = "number" -// colInfo.sql_type = "smallint" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "bit": -// colInfo.ts_type = "boolean" -// colInfo.sql_type = "boolean" -// break; -// case "float": -// colInfo.ts_type = "number" -// colInfo.sql_type = "float" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// break; -// case "bigint": -// colInfo.ts_type = "string" -// colInfo.sql_type = "bigint" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "date": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "date" -// break; -// case "time": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "time" -// break; -// case "datetime": -// colInfo.ts_type = "Date"; -// colInfo.sql_type = "datetime" -// break; -// case "char": -// colInfo.ts_type = "string" -// colInfo.sql_type = "char" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "nchar": -// colInfo.ts_type = "string" -// colInfo.sql_type = "nchar" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "text": -// colInfo.ts_type = "string" -// colInfo.sql_type = "text" -// break; -// case "ntext": -// colInfo.ts_type = "string" -// colInfo.sql_type = "ntext" -// break; -// case "uniqueidentifier": -// colInfo.ts_type = "string" -// colInfo.sql_type = "uniqueidentifier" -// break; -// case "varchar": -// colInfo.ts_type = "string" -// colInfo.sql_type = "varchar" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "binary": -// colInfo.ts_type = "Buffer" -// colInfo.sql_type = "binary" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "varbinary": -// colInfo.ts_type = "Buffer" -// colInfo.sql_type = "varbinary" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "image": -// colInfo.ts_type = "Buffer" -// colInfo.sql_type = "image" -// break; -// case "nvarchar": -// colInfo.ts_type = "string" -// colInfo.sql_type = "nvarchar" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "money": -// colInfo.ts_type = "number" -// colInfo.sql_type = "decimal" -// break; -// case "smallmoney": -// colInfo.ts_type = "number" -// colInfo.sql_type = "smallmoney" -// break; -// case "real": -// colInfo.ts_type = "number" -// colInfo.sql_type = "double" -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "decimal": -// colInfo.ts_type = "number" -// colInfo.sql_type = "decimal" -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// colInfo.numericScale = resp.NUMERIC_SCALE -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "numeric": -// colInfo.ts_type = "number" -// colInfo.sql_type = "numeric" -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// colInfo.numericScale = resp.NUMERIC_SCALE -// colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null; -// break; -// case "datetime2": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "datetime2" -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// break; -// case "time": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "time" -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// break; -// case "datetimeoffset": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "datetimeoffset" -// colInfo.numericPrecision = resp.NUMERIC_PRECISION -// break; -// case "smalldatetime": -// colInfo.ts_type = "Date" -// colInfo.sql_type = "smalldatetime" -// break; -// case "xml": -// colInfo.ts_type = "string" -// colInfo.sql_type = "text" -// break; -// default: -// console.error("Unknown column type:" + resp.DATA_TYPE); -// break; -// } + let response :any[][] = ( await this.Connection.execute(`SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH, + DATA_PRECISION, DATA_SCALE, IDENTITY_COLUMN + FROM USER_TAB_COLUMNS`)).rows!; + + entities.forEach((ent) => { + response.filter((filterVal) => { + return filterVal[0] == ent.EntityName; + }).forEach((resp) => { + let colInfo: ColumnInfo = new ColumnInfo(); + colInfo.name = resp[1]; + colInfo.is_nullable = resp[3] == 'Y' ? true : false; + colInfo.is_generated = resp[8] == 'YES' ? true : false; + colInfo.default = resp[2]; + switch (resp[4].toLowerCase()) { + case "number": + colInfo.ts_type = "number" + colInfo.sql_type = "int" + colInfo.char_max_lenght = resp[5] > 0 ? resp[5] : null; + break; + case "varchar2": + colInfo.ts_type = "number" + colInfo.sql_type = "smallint" + colInfo.char_max_lenght = resp[5] > 0 ? resp[5] : null; + break; + default: + console.error("Unknown column type:" + resp[4]); + break; + } -// if (colInfo.sql_type) ent.Columns.push(colInfo); -// }) -// }) + if (colInfo.sql_type) ent.Columns.push(colInfo); + }) + }) return entities; } async GetIndexesFromEntity(entities: EntityInfo[], schema: string): Promise { -// let request = new Oracle.Request(this.Connection) -// let response: { -// TableName: string, IndexName: string, ColumnName: string, is_unique: number, -// is_primary_key: number//, is_descending_key: number//, is_included_column: number -// }[] -// = (await request.query(`SELECT -// TableName = t.name, -// IndexName = ind.name, -// ColumnName = col.name, -// ind.is_unique, -// ind.is_primary_key -// -- ,ic.is_descending_key, -// -- ic.is_included_column -// FROM -// sys.indexes ind -// INNER JOIN -// sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id -// INNER JOIN -// sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id -// INNER JOIN -// sys.tables t ON ind.object_id = t.object_id -// INNER JOIN -// sys.schemas s on s.schema_id=t.schema_id -// WHERE -// t.is_ms_shipped = 0 and s.name='${schema}' -// ORDER BY -// t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset; -// entities.forEach((ent) => { -// response.filter((filterVal) => { -// return filterVal.TableName == ent.EntityName; -// }).forEach((resp) => { -// let indexInfo: IndexInfo = {}; -// let indexColumnInfo: IndexColumnInfo = {}; -// if (ent.Indexes.filter((filterVal) => { -// return filterVal.name == resp.IndexName -// }).length > 0) { -// indexInfo = ent.Indexes.filter((filterVal) => { -// return filterVal.name == resp.IndexName -// })[0]; -// } else { -// indexInfo.columns = []; -// indexInfo.name = resp.IndexName; -// indexInfo.isUnique = resp.is_unique == 1 ? true : false; -// indexInfo.isPrimaryKey = resp.is_primary_key == 1 ? true : false; -// ent.Indexes.push(indexInfo); -// } -// indexColumnInfo.name = resp.ColumnName; -// // indexColumnInfo.isIncludedColumn = resp.is_included_column == 1 ? true : false; -// // indexColumnInfo.isDescending = resp.is_descending_key == 1 ? true : false; -// indexInfo.columns.push(indexColumnInfo); + let response :any[][] = ( await this.Connection.execute(`SELECT ind.TABLE_NAME, ind.INDEX_NAME, col.COLUMN_NAME,ind.UNIQUENESS, CASE WHEN uc.CONSTRAINT_NAME IS NULL THEN 0 ELSE 1 END + FROM USER_INDEXES ind + JOIN USER_IND_COLUMNS col ON ind.INDEX_NAME=col.INDEX_NAME + LEFT JOIN USER_CONSTRAINTS uc ON uc.INDEX_NAME = ind.INDEX_NAME + ORDER BY col.INDEX_NAME ASC ,col.COLUMN_POSITION ASC`)).rows!; + + entities.forEach((ent) => { + response.filter((filterVal) => { + return filterVal[0] == ent.EntityName; + }).forEach((resp) => { + let indexInfo: IndexInfo = {}; + let indexColumnInfo: IndexColumnInfo = {}; + if (ent.Indexes.filter((filterVal) => { + return filterVal.name == resp[1] + }).length > 0) { + indexInfo = ent.Indexes.filter((filterVal) => { + return filterVal.name == resp[1] + })[0]; + } else { + indexInfo.columns = []; + indexInfo.name = resp[1]; + indexInfo.isUnique = resp[3] == 'UNIQUE' ? true : false; + indexInfo.isPrimaryKey = resp[4] == 1 ? true : false; + ent.Indexes.push(indexInfo); + } + indexColumnInfo.name = resp[2]; + // indexColumnInfo.isIncludedColumn = resp.is_included_column == 1 ? true : false; + // indexColumnInfo.isDescending = resp.is_descending_key == 1 ? true : false; + indexInfo.columns.push(indexColumnInfo); -// }) -// }) + }) + }) return entities; } async GetRelations(entities: EntityInfo[], schema: string): Promise { -// let request = new Oracle.Request(this.Connection) -// let response: { -// TableWithForeignKey: string, FK_PartNo: number, ForeignKeyColumn: string, -// TableReferenced: string, ForeignKeyColumnReferenced: string, -// onDelete: "RESTRICT" | "CASCADE" | "SET NULL", -// onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: number -// }[] -// = (await request.query(`select -// parentTable.name as TableWithForeignKey, -// fkc.constraint_column_id as FK_PartNo, -// parentColumn.name as ForeignKeyColumn, -// referencedTable.name as TableReferenced, -// referencedColumn.name as ForeignKeyColumnReferenced, -// fk.delete_referential_action_desc as onDelete, -// fk.update_referential_action_desc as onUpdate, -// fk.object_id -// from -// sys.foreign_keys fk -// inner join -// sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id -// inner join -// sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id -// inner join -// sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id -// inner join -// sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id -// inner join -// sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id -// inner join -// sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id -// where -// fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name='${schema}' -// order by -// TableWithForeignKey, FK_PartNo`)).recordset; -// let relationsTemp: RelationTempInfo[] = []; -// response.forEach((resp) => { -// let rels = relationsTemp.find((val) => { -// return val.object_id == resp.object_id; -// }) -// if (rels == undefined) { -// rels = {}; -// rels.ownerColumnsNames = []; -// rels.referencedColumnsNames = []; -// rels.actionOnDelete = resp.onDelete; -// rels.actionOnUpdate = resp.onUpdate; -// rels.object_id = resp.object_id; -// rels.ownerTable = resp.TableWithForeignKey; -// rels.referencedTable = resp.TableReferenced; -// relationsTemp.push(rels); -// } -// rels.ownerColumnsNames.push(resp.ForeignKeyColumn); -// rels.referencedColumnsNames.push(resp.ForeignKeyColumnReferenced); -// }) -// relationsTemp.forEach((relationTmp) => { -// let ownerEntity = entities.find((entitity) => { -// return entitity.EntityName == relationTmp.ownerTable; -// }) -// if (!ownerEntity) { -// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) -// return; -// } -// let referencedEntity = entities.find((entitity) => { -// return entitity.EntityName == relationTmp.referencedTable; -// }) -// if (!referencedEntity) { -// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) -// return; -// } -// let ownerColumn = ownerEntity.Columns.find((column) => { -// return column.name == relationTmp.ownerColumnsNames[0]; -// }) -// if (!ownerColumn) { -// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) -// return; -// } -// let relatedColumn = referencedEntity.Columns.find((column) => { -// return column.name == relationTmp.referencedColumnsNames[0]; -// }) -// if (!relatedColumn) { -// console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) -// return; -// } -// let ownColumn: ColumnInfo = ownerColumn; -// let isOneToMany: boolean; -// isOneToMany = false; -// let index = ownerEntity.Indexes.find( -// (index) => { -// return index.isUnique && index.columns.some(col => { -// return col.name == ownerColumn!.name -// }) -// } -// ) -// if (!index) { -// isOneToMany = true; -// } else { -// isOneToMany = false; -// } -// let ownerRelation = new RelationInfo() -// let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') -// if (referencedEntity.Columns.filter((filterVal) => { -// return filterVal.name == columnName; -// }).length > 0) { -// for (let i = 2; i <= ownerEntity.Columns.length; i++) { -// columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); -// if (referencedEntity.Columns.filter((filterVal) => { -// return filterVal.name == columnName; -// }).length == 0) break; -// } -// } -// ownerRelation.actionOnDelete = relationTmp.actionOnDelete -// ownerRelation.actionOnUpdate = relationTmp.actionOnUpdate -// ownerRelation.isOwner = true -// ownerRelation.relatedColumn = relatedColumn.name.toLowerCase() -// ownerRelation.relatedTable = relationTmp.referencedTable -// ownerRelation.ownerTable = relationTmp.ownerTable -// ownerRelation.ownerColumn = columnName -// ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne" -// ownerColumn.relations.push(ownerRelation) -// if (isOneToMany) { -// let col = new ColumnInfo() -// col.name = columnName -// let referencedRelation = new RelationInfo(); -// col.relations.push(referencedRelation) -// referencedRelation.actionOnDelete = relationTmp.actionOnDelete -// referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate -// referencedRelation.isOwner = false -// referencedRelation.relatedColumn = ownerColumn.name -// referencedRelation.relatedTable = relationTmp.ownerTable -// referencedRelation.ownerTable = relationTmp.referencedTable -// referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() -// referencedRelation.relationType = "OneToMany" -// referencedEntity.Columns.push(col) -// } else { -// let col = new ColumnInfo() -// col.name = columnName -// let referencedRelation = new RelationInfo(); -// col.relations.push(referencedRelation) -// referencedRelation.actionOnDelete = relationTmp.actionOnDelete -// referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate -// referencedRelation.isOwner = false -// referencedRelation.relatedColumn = ownerColumn.name -// referencedRelation.relatedTable = relationTmp.ownerTable -// referencedRelation.ownerTable = relationTmp.referencedTable -// referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() -// referencedRelation.relationType = "OneToOne" + let response :any[][] = ( await this.Connection.execute(`select owner.TABLE_NAME ownTbl,ownCol.POSITION,ownCol.COLUMN_NAME, + child.TABLE_NAME,childCol.COLUMN_NAME, + owner.DELETE_RULE, + 4,owner.CONSTRAINT_NAME + from user_constraints owner + join user_constraints child on owner.r_constraint_name=child.CONSTRAINT_NAME and child.constraint_type in ('P','U') + JOIN USER_CONS_COLUMNS ownCol ON owner.CONSTRAINT_NAME = ownCol.CONSTRAINT_NAME + JOIN USER_CONS_COLUMNS childCol ON child.CONSTRAINT_NAME = childCol.CONSTRAINT_NAME AND ownCol.POSITION=childCol.POSITION + ORDER BY ownTbl ASC, owner.CONSTRAINT_NAME ASC, ownCol.POSITION ASC`)).rows!; + -// referencedEntity.Columns.push(col) -// } -// }) + let relationsTemp: RelationTempInfo[] = []; + response.forEach((resp) => { + let rels = relationsTemp.find((val) => { + return val.object_id == resp[6]; + }) + if (rels == undefined) { + rels = {}; + rels.ownerColumnsNames = []; + rels.referencedColumnsNames = []; + rels.actionOnDelete = resp[5]; + rels.actionOnUpdate = "NO ACTION"; + rels.object_id = resp[6]; + rels.ownerTable = resp[0]; + rels.referencedTable = resp[3]; + relationsTemp.push(rels); + } + rels.ownerColumnsNames.push(resp[2]); + rels.referencedColumnsNames.push(resp[4]); + }) + relationsTemp.forEach((relationTmp) => { + let ownerEntity = entities.find((entitity) => { + return entitity.EntityName == relationTmp.ownerTable; + }) + if (!ownerEntity) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + return; + } + let referencedEntity = entities.find((entitity) => { + return entitity.EntityName == relationTmp.referencedTable; + }) + if (!referencedEntity) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + return; + } + let ownerColumn = ownerEntity.Columns.find((column) => { + return column.name == relationTmp.ownerColumnsNames[0]; + }) + if (!ownerColumn) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + return; + } + let relatedColumn = referencedEntity.Columns.find((column) => { + return column.name == relationTmp.referencedColumnsNames[0]; + }) + if (!relatedColumn) { + console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + return; + } + let ownColumn: ColumnInfo = ownerColumn; + let isOneToMany: boolean; + isOneToMany = false; + let index = ownerEntity.Indexes.find( + (index) => { + return index.isUnique && index.columns.some(col => { + return col.name == ownerColumn!.name + }) + } + ) + if (!index) { + isOneToMany = true; + } else { + isOneToMany = false; + } + let ownerRelation = new RelationInfo() + let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + if (referencedEntity.Columns.filter((filterVal) => { + return filterVal.name == columnName; + }).length > 0) { + for (let i = 2; i <= ownerEntity.Columns.length; i++) { + columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); + if (referencedEntity.Columns.filter((filterVal) => { + return filterVal.name == columnName; + }).length == 0) break; + } + } + ownerRelation.actionOnDelete = relationTmp.actionOnDelete + ownerRelation.actionOnUpdate = relationTmp.actionOnUpdate + ownerRelation.isOwner = true + ownerRelation.relatedColumn = relatedColumn.name.toLowerCase() + ownerRelation.relatedTable = relationTmp.referencedTable + ownerRelation.ownerTable = relationTmp.ownerTable + ownerRelation.ownerColumn = columnName + ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne" + ownerColumn.relations.push(ownerRelation) + if (isOneToMany) { + let col = new ColumnInfo() + col.name = columnName + let referencedRelation = new RelationInfo(); + col.relations.push(referencedRelation) + referencedRelation.actionOnDelete = relationTmp.actionOnDelete + referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate + referencedRelation.isOwner = false + referencedRelation.relatedColumn = ownerColumn.name + referencedRelation.relatedTable = relationTmp.ownerTable + referencedRelation.ownerTable = relationTmp.referencedTable + referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() + referencedRelation.relationType = "OneToMany" + referencedEntity.Columns.push(col) + } else { + let col = new ColumnInfo() + col.name = columnName + let referencedRelation = new RelationInfo(); + col.relations.push(referencedRelation) + referencedRelation.actionOnDelete = relationTmp.actionOnDelete + referencedRelation.actionOnUpdate = relationTmp.actionOnUpdate + referencedRelation.isOwner = false + referencedRelation.relatedColumn = ownerColumn.name + referencedRelation.relatedTable = relationTmp.ownerTable + referencedRelation.ownerTable = relationTmp.referencedTable + referencedRelation.ownerColumn = relatedColumn.name.toLowerCase() + referencedRelation.relationType = "OneToOne" + + referencedEntity.Columns.push(col) + } + }) return entities; } async DisconnectFromServer() { @@ -455,22 +278,7 @@ export class OracleDriver extends AbstractDriver { await promise; } - // connection.execute( - // `SELECT department_id, department_name - // FROM departments - // WHERE manager_id < :id`, - // [110], // bind value for :id - // function(err, result) - // { - // if (err) { - // console.error(err.message); - // doRelease(connection); - // return; - // } - // console.log(result.rows); - // doRelease(connection); - // }); - + async CreateDB(dbName: string) { } diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 3b6a5be..37afee5 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -191,7 +191,7 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str export async function createOracleDBModels(filesOrgPath: string, resultsPath: string): Promise { let driver: AbstractDriver; driver = new OracleDriver(); - await driver.ConnectToServer(`mysql`, String(process.env.ORACLE_Host), Number(process.env.ORACLE_Port), String(process.env.ORACLE_Username), String(process.env.ORACLE_Password), yn(process.env.ORACLE_SSL)); + await driver.ConnectToServer(String(process.env.ORACLE_Database), String(process.env.ORACLE_Host), Number(process.env.ORACLE_Port), String(process.env.ORACLE_Username), String(process.env.ORACLE_Password), yn(process.env.ORACLE_SSL)); if (! await driver.CheckIfDBExists(String(process.env.ORACLE_Database))) await driver.CreateDB(String(process.env.ORACLE_Database)); From c5e181602a21550ebda74da73dd701f116014a21 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 25 Dec 2017 19:56:17 +0100 Subject: [PATCH 06/21] updating typeorm --- package-lock.json | 281 ++++++++++++------ package.json | 2 +- .../sample2-one-to-one/entity/Post.ts | 32 +- .../sample2-one-to-one/entity/PostDetails.ts | 11 +- .../entity/PostInformation.ts | 10 +- .../sample3-many-to-one/entity/Post.ts | 30 +- .../sample3-many-to-one/entity/PostDetails.ts | 9 +- .../entity/PostInformation.ts | 8 +- test/utils/EntityFileToJson.ts | 2 + test/utils/GeneralTestUtils.ts | 3 +- 10 files changed, 237 insertions(+), 151 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0bf8d84..ec3166a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,8 +70,7 @@ "@types/node": { "version": "8.0.53", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.53.tgz", - "integrity": "sha512-54Dm6NwYeiSQmRB1BLXKr5GELi0wFapR1npi8bnZhEcu84d/yQKqnwwXQ56hZ0RUbTG6L5nqDZaN3dgByQXQRQ==", - "dev": true + "integrity": "sha512-54Dm6NwYeiSQmRB1BLXKr5GELi0wFapR1npi8bnZhEcu84d/yQKqnwwXQ56hZ0RUbTG6L5nqDZaN3dgByQXQRQ==" }, "@types/oracledb": { "version": "1.11.34", @@ -530,56 +529,6 @@ "restore-cursor": "1.0.1" } }, - "cli-highlight": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-1.1.4.tgz", - "integrity": "sha1-5FWQwU+xjhOGXjiZ6CTFWSzCKSY=", - "requires": { - "chalk": "1.1.3", - "he": "1.1.1", - "highlight.js": "9.12.0", - "mz": "2.7.0", - "yargs": "4.8.1" - }, - "dependencies": { - "cliui": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", - "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", - "requires": { - "string-width": "1.0.2", - "strip-ansi": "3.0.1", - "wrap-ansi": "2.1.0" - } - }, - "window-size": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.2.0.tgz", - "integrity": "sha1-tDFbtCFKPXBY6+7okuE/ok2YsHU=" - }, - "yargs": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", - "integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=", - "requires": { - "cliui": "3.2.0", - "decamelize": "1.2.0", - "get-caller-file": "1.0.2", - "lodash.assign": "4.2.0", - "os-locale": "1.4.0", - "read-pkg-up": "1.0.1", - "require-directory": "2.1.1", - "require-main-filename": "1.0.1", - "set-blocking": "2.0.0", - "string-width": "1.0.2", - "which-module": "1.0.0", - "window-size": "0.2.0", - "y18n": "3.2.1", - "yargs-parser": "2.4.1" - } - } - } - }, "cli-truncate": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-1.0.0.tgz", @@ -1058,6 +1007,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "dev": true, "requires": { "path-exists": "2.1.0", "pinkie-promise": "2.0.1" @@ -1346,7 +1296,8 @@ "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", - "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=" + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true }, "highlight.js": { "version": "9.12.0", @@ -1582,7 +1533,8 @@ "is-utf8": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", - "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=" + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=", + "dev": true }, "is-windows": { "version": "0.2.0", @@ -1821,6 +1773,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "dev": true, "requires": { "graceful-fs": "4.1.11", "parse-json": "2.2.0", @@ -1905,11 +1858,6 @@ "integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=", "dev": true }, - "lodash.assign": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=" - }, "lodash.escape": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-3.2.0.tgz", @@ -2457,14 +2405,6 @@ "resolved": "https://registry.npmjs.org/oracledb/-/oracledb-2.0.15.tgz", "integrity": "sha1-9+IBtp+ngjUIFV6fNKumXVdCbx0=" }, - "os-locale": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", - "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", - "requires": { - "lcid": "1.0.0" - } - }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", @@ -2513,10 +2453,19 @@ "error-ex": "1.3.1" } }, + "parse5": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", + "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", + "requires": { + "@types/node": "8.0.53" + } + }, "path-exists": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "dev": true, "requires": { "pinkie-promise": "2.0.1" } @@ -2553,6 +2502,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "dev": true, "requires": { "graceful-fs": "4.1.11", "pify": "2.3.0", @@ -2646,12 +2596,14 @@ "pinkie": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", + "dev": true }, "pinkie-promise": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "dev": true, "requires": { "pinkie": "2.0.4" } @@ -2787,6 +2739,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "dev": true, "requires": { "load-json-file": "1.1.0", "normalize-package-data": "2.3.8", @@ -2797,6 +2750,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "dev": true, "requires": { "find-up": "1.1.2", "read-pkg": "1.1.0" @@ -3211,6 +3165,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "dev": true, "requires": { "is-utf8": "0.2.1" } @@ -3409,13 +3364,14 @@ "dev": true }, "typeorm": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.1.3.tgz", - "integrity": "sha512-5c+TMBuVqzet2LHrf5ZfkVaa7U89Vr8mlbSxONUQT+l4f+pvFcBHcWNOYFRN9bfrw+kKBGzCavTBYHbm3bmHSQ==", + "version": "0.2.0-alpha.13", + "resolved": "https://registry.npmjs.org/typeorm/-/typeorm-0.2.0-alpha.13.tgz", + "integrity": "sha512-xYSqRU0UF/O3ofXTSktzqrtFVwSze9knH2bucVoE+iC9tROq3ndlu9brLxY50jBLskVJpIJT73dHhpdpmqzhPA==", "requires": { "app-root-path": "2.0.1", "chalk": "2.3.0", - "cli-highlight": "1.1.4", + "cli-highlight": "1.2.3", + "debug": "3.1.0", "dotenv": "4.0.0", "glob": "7.1.2", "js-yaml": "3.8.4", @@ -3426,6 +3382,11 @@ "yargs": "9.0.1" }, "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + }, "ansi-styles": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", @@ -3434,6 +3395,11 @@ "color-convert": "1.9.1" } }, + "camelcase": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" + }, "chalk": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", @@ -3444,11 +3410,148 @@ "supports-color": "4.5.0" } }, + "cli-highlight": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/cli-highlight/-/cli-highlight-1.2.3.tgz", + "integrity": "sha512-cmc4Y2kJuEpT2KZd9pgWWskpDMMfJu2roIcY1Ya/aIItufF5FKsV/NtA6vvdhSUllR8KJfvQDNmIcskU+MKLDg==", + "requires": { + "chalk": "2.3.0", + "highlight.js": "9.12.0", + "mz": "2.7.0", + "parse5": "3.0.3", + "yargs": "10.0.3" + }, + "dependencies": { + "yargs": { + "version": "10.0.3", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-10.0.3.tgz", + "integrity": "sha512-DqBpQ8NAUX4GyPP/ijDGHsJya4tYqLQrjPr95HNsr1YwL3+daCfvBwg7+gIC6IdJhR2kATh3hb61vjzMWEtjdw==", + "requires": { + "cliui": "3.2.0", + "decamelize": "1.2.0", + "find-up": "2.1.0", + "get-caller-file": "1.0.2", + "os-locale": "2.1.0", + "require-directory": "2.1.1", + "require-main-filename": "1.0.1", + "set-blocking": "2.0.0", + "string-width": "2.1.1", + "which-module": "2.0.0", + "y18n": "3.2.1", + "yargs-parser": "8.1.0" + } + } + } + }, + "cliui": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "requires": { + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wrap-ansi": "2.1.0" + }, + "dependencies": { + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + } + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "execa": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", + "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", + "requires": { + "cross-spawn": "5.1.0", + "get-stream": "3.0.0", + "is-stream": "1.1.0", + "npm-run-path": "2.0.2", + "p-finally": "1.0.0", + "signal-exit": "3.0.2", + "strip-eof": "1.0.0" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "requires": { + "locate-path": "2.0.0" + } + }, "has-flag": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "npm-run-path": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", + "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "requires": { + "path-key": "2.0.1" + } + }, + "os-locale": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz", + "integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==", + "requires": { + "execa": "0.7.0", + "lcid": "1.0.0", + "mem": "1.1.0" + } + }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "requires": { + "is-fullwidth-code-point": "2.0.0", + "strip-ansi": "4.0.0" + }, + "dependencies": { + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "requires": { + "ansi-regex": "3.0.0" + } + } + } + }, "supports-color": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", @@ -3456,6 +3559,19 @@ "requires": { "has-flag": "2.0.0" } + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + }, + "yargs-parser": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-8.1.0.tgz", + "integrity": "sha512-yP+6QqN8BmrgW2ggLtTbdrOyBNSI7zBa4IykmiV5R1wl1JWNxQvWhMfMdmzIYtKU7oP3OOInY/tl2ov3BDjnJQ==", + "requires": { + "camelcase": "4.1.0" + } } } }, @@ -3705,11 +3821,6 @@ "isexe": "2.0.0" } }, - "which-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz", - "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=" - }, "widest-line": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-1.0.0.tgz", @@ -3979,22 +4090,6 @@ } } }, - "yargs-parser": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", - "integrity": "sha1-hVaN488VD/SfpRgl8DqMiA3cxcQ=", - "requires": { - "camelcase": "3.0.0", - "lodash.assign": "4.2.0" - }, - "dependencies": { - "camelcase": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", - "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" - } - } - }, "yn": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", diff --git a/package.json b/package.json index 2dffad6..da0f0a4 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "oracledb": "^2.0.15", "pg": "^6.4.2", "reflect-metadata": "^0.1.10", - "typeorm": "^0.1.3", + "typeorm": "^0.2.0-alpha.13", "typescript": "^2.6.1", "yargs": "^9.0.1", "yn": "^2.0.0" diff --git a/test/integration/examples/sample2-one-to-one/entity/Post.ts b/test/integration/examples/sample2-one-to-one/entity/Post.ts index 7a8efe0..cec9818 100644 --- a/test/integration/examples/sample2-one-to-one/entity/Post.ts +++ b/test/integration/examples/sample2-one-to-one/entity/Post.ts @@ -1,10 +1,10 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn,Index} from "typeorm"; -import {PostDetails} from "./PostDetails"; -import {PostCategory} from "./PostCategory"; -import {PostAuthor} from "./PostAuthor"; -import {PostInformation} from "./PostInformation"; -import {PostImage} from "./PostImage"; -import {PostMetadata} from "./PostMetadata"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } from "typeorm"; +import { PostDetails } from "./PostDetails"; +import { PostCategory } from "./PostCategory"; +import { PostAuthor } from "./PostAuthor"; +import { PostInformation } from "./PostInformation"; +import { PostImage } from "./PostImage"; +import { PostMetadata } from "./PostMetadata"; @Entity("Post") export class Post { @@ -20,9 +20,8 @@ export class Post { // post has relation with category, however inverse relation is not set (category does not have relation with post set) @OneToOne(type => PostCategory, { - cascadeInsert: true, - cascadeUpdate: true, - cascadeRemove: true + cascade: true, + onDelete: 'CASCADE' }) @JoinColumn() @Index({ unique: true }) @@ -31,7 +30,7 @@ export class Post { // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this // relation it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostDetails, details => details.post, { - cascadeInsert: true + cascade: true }) @JoinColumn() @Index({ unique: true }) @@ -40,7 +39,7 @@ export class Post { // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostImage, image => image.post, { - cascadeUpdate: true + cascade: true, }) @JoinColumn() @Index({ unique: true }) @@ -49,17 +48,16 @@ export class Post { // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostMetadata, metadata => metadata.post, { - cascadeRemove: true + onDelete: 'CASCADE' }) @JoinColumn() @Index({ unique: true }) - metadata: PostMetadata|null; + metadata: PostMetadata | null; // post has relation with details. full cascades here @OneToOne(type => PostInformation, information => information.post, { - cascadeInsert: true, - cascadeUpdate: true, - cascadeRemove: true + cascade: true, + onDelete: 'CASCADE' }) @JoinColumn() @Index({ unique: true }) diff --git a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts index ca47932..917af60 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts @@ -1,5 +1,5 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; -import {Post} from "./Post"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; +import { Post } from "./Post"; @Entity("PostDetails") export class PostDetails { @@ -15,11 +15,10 @@ export class PostDetails { @Column() metadata: string; - + @OneToOne(type => Post, post => post.details, { - cascadeInsert: true, - cascadeUpdate: true, - cascadeRemove: true + // cascade: true, + onDelete: 'CASCADE' }) post: Post; diff --git a/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts b/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts index 60229c4..0673ca4 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts @@ -1,5 +1,5 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; -import {Post} from "./Post"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; +import { Post } from "./Post"; @Entity("PostInformation") export class PostInformation { @@ -9,10 +9,8 @@ export class PostInformation { @Column() text: string; - - @OneToOne(type => Post, post => post.information, { - cascadeUpdate: true, - }) + + @OneToOne(type => Post, post => post.information) post: Post; } \ No newline at end of file diff --git a/test/integration/examples/sample3-many-to-one/entity/Post.ts b/test/integration/examples/sample3-many-to-one/entity/Post.ts index 89a3aa5..36b60ea 100644 --- a/test/integration/examples/sample3-many-to-one/entity/Post.ts +++ b/test/integration/examples/sample3-many-to-one/entity/Post.ts @@ -1,10 +1,10 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, OneToMany, ManyToOne, JoinColumn } from "typeorm"; -import {PostDetails} from "./PostDetails"; -import {PostCategory} from "./PostCategory"; -import {PostAuthor} from "./PostAuthor"; -import {PostInformation} from "./PostInformation"; -import {PostImage} from "./PostImage"; -import {PostMetadata} from "./PostMetadata"; +import { PostDetails } from "./PostDetails"; +import { PostCategory } from "./PostCategory"; +import { PostAuthor } from "./PostAuthor"; +import { PostInformation } from "./PostInformation"; +import { PostImage } from "./PostImage"; +import { PostMetadata } from "./PostMetadata"; @Entity("Post") export class Post { @@ -20,38 +20,36 @@ export class Post { // post has relation with category, however inverse relation is not set (category does not have relation with post set) @ManyToOne(type => PostCategory, { - cascadeInsert: true, - cascadeUpdate: true, - cascadeRemove: true + cascade: true, + onDelete: 'CASCADE' }) category: PostCategory; // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this // relation it will be inserted automatically to the db when you save this Post entity @ManyToOne(type => PostDetails, details => details.posts, { - cascadeInsert: true + cascade: true, }) details: PostDetails; // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @ManyToOne(type => PostImage, image => image.posts, { - cascadeUpdate: true + cascade: true, }) image: PostImage; // post has relation with details. cascade update here means if new PostDetail instance will be set to this relation // it will be inserted automatically to the db when you save this Post entity @ManyToOne(type => PostMetadata, metadata => metadata.posts, { - cascadeRemove: true + cascade: true, }) - metadata: PostMetadata|null; + metadata: PostMetadata | null; // post has relation with details. full cascades here @ManyToOne(type => PostInformation, information => information.posts, { - cascadeInsert: true, - cascadeUpdate: true, - cascadeRemove: true + cascade: true, + onDelete: 'CASCADE' }) information: PostInformation; diff --git a/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts b/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts index 0f96397..4cf9d2c 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts @@ -1,5 +1,5 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, OneToMany, ManyToOne, JoinColumn } from "typeorm"; -import {Post} from "./Post"; +import { Post } from "./Post"; @Entity("PostDetails") export class PostDetails { @@ -21,11 +21,8 @@ export class PostDetails { nullable: true }) metadata: string; - - @OneToMany(type => Post, post => post.details, { - cascadeInsert: true, - cascadeUpdate: true - }) + + @OneToMany(type => Post, post => post.details) posts: Post[]; } \ No newline at end of file diff --git a/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts b/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts index a2b9b20..def7ca5 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts @@ -1,5 +1,5 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, OneToMany, ManyToOne, JoinColumn } from "typeorm"; -import {Post} from "./Post"; +import { Post } from "./Post"; @Entity("PostInformation") export class PostInformation { @@ -9,10 +9,8 @@ export class PostInformation { @Column() text: string; - - @OneToMany(type => Post, post => post.information, { - cascadeUpdate: true, - }) + + @OneToMany(type => Post, post => post.information) posts: Post[]; } \ No newline at end of file diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index 0d09b92..9ea6b4f 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -21,6 +21,7 @@ export class EntityFileToJson { // if (!x.endsWith('[]')) { // x = x + '[]'// can't distinguish OneTwoMany from OneToOne without indexes // } + x=x.trim(); return x; }); } else { @@ -243,6 +244,7 @@ export class EntityFileToJson { // if (!x.endsWith('[]')) { // x = x + '[]'// can't distinguish OneTwoMany from OneToOne without indexes // } + x=x.trim(); return x; }); diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 37afee5..65e5fdb 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -200,12 +200,13 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st let connOpt: ConnectionOptions = { database: String(process.env.ORACLE_Database), + sid: String(process.env.ORACLE_Database), host: String(process.env.ORACLE_Host), password: String(process.env.ORACLE_Password), type: 'oracle', username: String(process.env.ORACLE_Username), port: Number(process.env.ORACLE_Port), - dropSchema: true, + // dropSchema: true, synchronize: true, entities: [path.resolve(filesOrgPath, '*.js')], } From 4de7284ded002316c6c91240be9832bc12056842 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 25 Dec 2017 19:58:04 +0100 Subject: [PATCH 07/21] Disabling oracle CI tests - need better support by typeorm for oracle tests to pass --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5ec5dc9..1f3e8bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ services: - docker env: - - POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=postgres POSTGRES_Password=!Passw0rd POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=!Passw0rd MYSQL_Database=typeorm_mg MYSQL_SSL=1 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 MARIADB_Username=root MARIADB_Password=!Passw0rd MARIADB_Database=typeorm_mg MARIADB_SSL=0 ORACLE_Skip=0 ORACLE_Host=localhost ORACLE_Port=1521 ORACLE_Username=system ORACLE_Password=Oradoc_db1 ORACLE_Database=ORCLCDB ORACLE_SSL=0 + - POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=postgres POSTGRES_Password=!Passw0rd POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=!Passw0rd MYSQL_Database=typeorm_mg MYSQL_SSL=1 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 MARIADB_Username=root MARIADB_Password=!Passw0rd MARIADB_Database=typeorm_mg MARIADB_SSL=0 before_install: - sudo service mysql stop From 3680cf61a63a3c1875117481ff75037020a31a94 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 25 Dec 2017 20:25:35 +0100 Subject: [PATCH 08/21] Removed dependency on Oracle Client Library when not using Oracle Driver --- src/drivers/OracleDriver.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 7d4eb6c..81bdb82 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -1,14 +1,30 @@ import { AbstractDriver } from './AbstractDriver' -import * as Oracle from 'oracledb' import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' import {promisify} from 'util' +import { request } from 'https'; + + /** * OracleDriver */ -export class OracleDriver extends AbstractDriver { + export class OracleDriver extends AbstractDriver { + Oracle:any; + constructor() { + super(); + try { + this.Oracle= require('oracledb') + } catch (error) { + console.error(error); + process.abort(); + throw error; + } + + } + + FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); @@ -243,9 +259,9 @@ export class OracleDriver extends AbstractDriver { await this.Connection.close(); } - private Connection: Oracle.IConnection; + private Connection: any/*Oracle.IConnection*/; async ConnectToServer(database: string, server: string, port: number, user: string, password: string, ssl: boolean) { - let config: Oracle.IConnectionAttributes = { + let config: any/*Oracle.IConnectionAttributes*/ = { user: user, password: password, // connectString: `${server}:${port}/ORCLCDB.localdomain/${database}`, @@ -257,7 +273,7 @@ export class OracleDriver extends AbstractDriver { let that=this; let promise = new Promise( (resolve, reject) => { - Oracle.getConnection( + this.Oracle.getConnection( config, function (err, connection) { if (!err) { From 61db5095d4c038e0d0664419d1a369c7e21d8b1f Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 26 Dec 2017 12:56:23 +0100 Subject: [PATCH 09/21] codecov settings changed --- codecov.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 54910f4..a0252e6 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,9 @@ parsers: javascript: - enable_partials: yes \ No newline at end of file + enable_partials: yes +comment: + layout: diff + behavior: default +codecov: + notify: + require_ci_to_pass: no From 78e59fafdae73affc560a51827a76022314c6838 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sat, 30 Dec 2017 15:12:34 +0100 Subject: [PATCH 10/21] disabling mssql, oracle images on CI build --- docker-compose.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 645b9c5..5884c91 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,21 +29,21 @@ services: POSTGRES_PASSWORD: "!Passw0rd" # mssql - mssql: - image: "microsoft/mssql-server-linux:2017-GA" - container_name: "typeorm-mg-mssql" - ports: - - "1433:1433" - environment: - ACCEPT_EULA: "Y" - SA_PASSWORD: "!Passw0rd" + # mssql: + # image: "microsoft/mssql-server-linux:2017-GA" + # container_name: "typeorm-mg-mssql" + # ports: + # - "1433:1433" + # environment: + # ACCEPT_EULA: "Y" + # SA_PASSWORD: "!Passw0rd" # oracle - oracle: - image: "store/oracle/database-enterprise:12.2.0.1-slim" - container_name: "typeorm-mg-oracle" - ports: - - "1521:1521" + # oracle: + # image: "store/oracle/database-enterprise:12.2.0.1-slim" + # container_name: "typeorm-mg-oracle" + # ports: + # - "1521:1521" # environment: # DB_SID: "ORCLCDB" # SYS_PASSWORD: "Oradoc_db1" From 88f46ecfd89f15a21588e5468e9b078f7a203ecd Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sat, 30 Dec 2017 16:04:10 +0100 Subject: [PATCH 11/21] Added editorconfig --- .editorconfig | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..08891d8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true \ No newline at end of file From f82fa172c9ac61116b5c1f14bbd2aaf6c4928a19 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sat, 30 Dec 2017 23:53:59 +0100 Subject: [PATCH 12/21] all db specific tests run in same db driver order --- test/integration/entityTypes.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/entityTypes.test.ts b/test/integration/entityTypes.test.ts index 6102403..6e33b2c 100644 --- a/test/integration/entityTypes.test.ts +++ b/test/integration/entityTypes.test.ts @@ -30,9 +30,9 @@ describe("Platform specyfic types", async function () { let examplesPathTS = path.resolve(process.cwd(), 'test/integration/entityTypes') let files = fs.readdirSync(examplesPathTS) - for (let folder of files) { + for (let dbDriver of dbDrivers) { - for (let dbDriver of dbDrivers) { + for (let folder of files) { if (dbDriver == folder) { it(dbDriver, async function () { From a07f347e4b26d15fbc3305f796718d55a0662966 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 31 Dec 2017 01:20:53 +0100 Subject: [PATCH 13/21] better handling fatal errors, codecov treshold set --- codecov.yml | 7 +++- src/Engine.ts | 5 +-- src/Utils.ts | 12 +++++++ src/drivers/MssqlDriver.ts | 66 +++++++++++++++++------------------ src/drivers/MysqlDriver.ts | 39 ++++++++++----------- src/drivers/OracleDriver.ts | 48 ++++++++++++------------- src/drivers/PostgresDriver.ts | 23 ++++++------ src/index.ts | 16 ++++----- src/typings.d.ts | 4 +++ 9 files changed, 117 insertions(+), 103 deletions(-) create mode 100644 src/Utils.ts create mode 100644 src/typings.d.ts diff --git a/codecov.yml b/codecov.yml index a0252e6..176f14b 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,4 +6,9 @@ comment: behavior: default codecov: notify: - require_ci_to_pass: no + require_ci_to_pass: no +coverage: + status: + project: + default: + threshold: 5% diff --git a/src/Engine.ts b/src/Engine.ts index 09aa4fb..f2f8d2d 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -3,6 +3,7 @@ import { DatabaseModel } from './models/DatabaseModel' import * as Handlebars from 'handlebars' import fs = require('fs'); import path = require('path') +import * as TomgUtils from './Utils' /** * Engine */ @@ -15,7 +16,7 @@ export class Engine { if (dbModel.entities.length > 0) { this.createModelFromMetadata(dbModel); } else { - console.error('Tables not found in selected database. Skipping creation of typeorm model.'); + TomgUtils.LogFatalError('Tables not found in selected database. Skipping creation of typeorm model.',false); } return true; } @@ -84,4 +85,4 @@ export interface EngineOptions { databaseType: string, schemaName:string, ssl:boolean -} \ No newline at end of file +} diff --git a/src/Utils.ts b/src/Utils.ts new file mode 100644 index 0000000..ae1b70d --- /dev/null +++ b/src/Utils.ts @@ -0,0 +1,12 @@ + +import * as data from './../../package.json' +export function LogFatalError(errText:string, isABug:boolean=true,errObject?:any) { +let x = data; + console.error(`Fatal error occured.`) + console.error(`${x.name}@${x.version} node@${process.version}`) + console.error(`Fatal error occured in typeorm-model-generator.`) + console.error(`If this is a bug please open an issue including this log on ${x.bugs.url}`) + if (isABug&&!errObject) errObject=new Error().stack + if (!!errObject) console.error(errObject) + process.abort() +} diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index 2fa64d4..06c8fe1 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -4,6 +4,8 @@ import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' +import * as TomgUtils from './../Utils' + /** * MssqlDriver */ @@ -12,7 +14,7 @@ export class MssqlDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - console.error(`Table ${entity.EntityName} has no PK.`) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) return; } entity.Columns.forEach(col => { @@ -194,7 +196,7 @@ export class MssqlDriver extends AbstractDriver { colInfo.sql_type = "text" break; default: - console.error("Unknown column type:" + resp.DATA_TYPE); + TomgUtils.LogFatalError("Unknown column type:" + resp.DATA_TYPE); break; } @@ -209,7 +211,7 @@ export class MssqlDriver extends AbstractDriver { TableName: string, IndexName: string, ColumnName: string, is_unique: number, is_primary_key: number//, is_descending_key: number//, is_included_column: number }[] - = (await request.query(`SELECT + = (await request.query(`SELECT TableName = t.name, IndexName = ind.name, ColumnName = col.name, @@ -217,19 +219,19 @@ export class MssqlDriver extends AbstractDriver { ind.is_primary_key -- ,ic.is_descending_key, -- ic.is_included_column -FROM - sys.indexes ind -INNER JOIN - sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id -INNER JOIN - sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id -INNER JOIN - sys.tables t ON ind.object_id = t.object_id +FROM + sys.indexes ind +INNER JOIN + sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id +INNER JOIN + sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id +INNER JOIN + sys.tables t ON ind.object_id = t.object_id INNER JOIN sys.schemas s on s.schema_id=t.schema_id -WHERE +WHERE t.is_ms_shipped = 0 and s.name='${schema}' -ORDER BY +ORDER BY t.name, ind.name, ind.index_id, ic.key_ordinal;`)).recordset; entities.forEach((ent) => { response.filter((filterVal) => { @@ -268,32 +270,32 @@ ORDER BY onDelete: "RESTRICT" | "CASCADE" | "SET NULL", onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: number }[] - = (await request.query(`select - parentTable.name as TableWithForeignKey, + = (await request.query(`select + parentTable.name as TableWithForeignKey, fkc.constraint_column_id as FK_PartNo, parentColumn.name as ForeignKeyColumn, - referencedTable.name as TableReferenced, + referencedTable.name as TableReferenced, referencedColumn.name as ForeignKeyColumnReferenced, fk.delete_referential_action_desc as onDelete, fk.update_referential_action_desc as onUpdate, fk.object_id -from - sys.foreign_keys fk -inner join +from + sys.foreign_keys fk +inner join sys.foreign_key_columns as fkc on fkc.constraint_object_id=fk.object_id -inner join +inner join sys.tables as parentTable on fkc.parent_object_id = parentTable.object_id -inner join +inner join sys.columns as parentColumn on fkc.parent_object_id = parentColumn.object_id and fkc.parent_column_id = parentColumn.column_id -inner join +inner join sys.tables as referencedTable on fkc.referenced_object_id = referencedTable.object_id -inner join +inner join sys.columns as referencedColumn on fkc.referenced_object_id = referencedColumn.object_id and fkc.referenced_column_id = referencedColumn.column_id inner join sys.schemas as parentSchema on parentSchema.schema_id=parentTable.schema_id -where +where fk.is_disabled=0 and fk.is_ms_shipped=0 and parentSchema.name='${schema}' -order by +order by TableWithForeignKey, FK_PartNo`)).recordset; let relationsTemp: RelationTempInfo[] = []; response.forEach((resp) => { @@ -319,28 +321,28 @@ order by return entitity.EntityName == relationTmp.ownerTable; }) if (!ownerEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) return; } let referencedEntity = entities.find((entitity) => { return entitity.EntityName == relationTmp.referencedTable; }) if (!referencedEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) return; } let ownerColumn = ownerEntity.Columns.find((column) => { return column.name == relationTmp.ownerColumnsNames[0]; }) if (!ownerColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) return; } let relatedColumn = referencedEntity.Columns.find((column) => { return column.name == relationTmp.referencedColumnsNames[0]; }) if (!relatedColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) return; } let ownColumn: ColumnInfo = ownerColumn; @@ -440,9 +442,7 @@ order by resolve(true) } else { - console.error('Error connecting to MSSQL Server.') - console.error(err.message) - process.abort() + TomgUtils.LogFatalError('Error connecting to MSSQL Server.',false,err.message) reject(err) } }); @@ -468,4 +468,4 @@ order by let resp = await request.query(`SELECT name FROM master.sys.databases WHERE name = N'${dbName}' `) return resp.recordset.length > 0; } -} \ No newline at end of file +} diff --git a/src/drivers/MysqlDriver.ts b/src/drivers/MysqlDriver.ts index e279b47..92aca50 100644 --- a/src/drivers/MysqlDriver.ts +++ b/src/drivers/MysqlDriver.ts @@ -4,6 +4,7 @@ import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' +import * as TomgUtils from './../Utils' /** * MysqlDriver */ @@ -14,7 +15,7 @@ export class MysqlDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - console.error(`Table ${entity.EntityName} has no PK.`) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) return; } entity.Columns.forEach(col => { @@ -196,7 +197,7 @@ export class MysqlDriver extends AbstractDriver { colInfo.sql_type = "json" break; default: - console.error("Unknown column type:" + resp.DATA_TYPE); + TomgUtils.LogFatalError("Unknown column type:" + resp.DATA_TYPE); break; } if (colInfo.sql_type) ent.Columns.push(colInfo); @@ -208,7 +209,7 @@ export class MysqlDriver extends AbstractDriver { let response = await this.ExecQuery<{ TableName: string, IndexName: string, ColumnName: string, is_unique: number, is_primary_key: number//, is_descending_key: number//, is_included_column: number - }>(`SELECT TABLE_NAME TableName,INDEX_NAME IndexName,COLUMN_NAME ColumnName,CASE WHEN NON_UNIQUE=0 THEN 1 ELSE 0 END is_unique, + }>(`SELECT TABLE_NAME TableName,INDEX_NAME IndexName,COLUMN_NAME ColumnName,CASE WHEN NON_UNIQUE=0 THEN 1 ELSE 0 END is_unique, CASE WHEN INDEX_NAME='PRIMARY' THEN 1 ELSE 0 END is_primary_key FROM information_schema.statistics sta WHERE table_schema like DATABASE(); @@ -248,22 +249,22 @@ export class MysqlDriver extends AbstractDriver { TableReferenced: string, ForeignKeyColumnReferenced: string, onDelete: "RESTRICT" | "CASCADE" | "SET NULL", onUpdate: "RESTRICT" | "CASCADE" | "SET NULL", object_id: string - }>(`SELECT - CU.TABLE_NAME TableWithForeignKey, + }>(`SELECT + CU.TABLE_NAME TableWithForeignKey, CU.ORDINAL_POSITION FK_PartNo, - CU.COLUMN_NAME ForeignKeyColumn, - CU.REFERENCED_TABLE_NAME TableReferenced, + CU.COLUMN_NAME ForeignKeyColumn, + CU.REFERENCED_TABLE_NAME TableReferenced, CU.REFERENCED_COLUMN_NAME ForeignKeyColumnReferenced, RC.DELETE_RULE onDelete, RC.UPDATE_RULE onUpdate, CU.CONSTRAINT_NAME object_id FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU - JOIN + JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC ON CU.CONSTRAINT_NAME=RC.CONSTRAINT_NAME WHERE - TABLE_SCHEMA = SCHEMA() - AND CU.REFERENCED_TABLE_NAME IS NOT NULL; + TABLE_SCHEMA = SCHEMA() + AND CU.REFERENCED_TABLE_NAME IS NOT NULL; `); let relationsTemp: RelationTempInfo[] = []; response.forEach((resp) => { @@ -289,28 +290,28 @@ export class MysqlDriver extends AbstractDriver { return entitity.EntityName == relationTmp.ownerTable; }) if (!ownerEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) return; } let referencedEntity = entities.find((entitity) => { return entitity.EntityName == relationTmp.referencedTable; }) if (!referencedEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) return; } let ownerColumn = ownerEntity.Columns.find((column) => { return column.name == relationTmp.ownerColumnsNames[0]; }) if (!ownerColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) return; } let relatedColumn = referencedEntity.Columns.find((column) => { return column.name == relationTmp.referencedColumnsNames[0]; }) if (!relatedColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) return; } let ownColumn: ColumnInfo = ownerColumn; @@ -391,9 +392,7 @@ export class MysqlDriver extends AbstractDriver { resolve(true) } else { - console.error(`Error disconnecting to ${this.EngineName} Server.`) - console.error(err.message) - process.abort() + TomgUtils.LogFatalError(`Error disconnecting to ${this.EngineName} Server.`,false,err.message) reject(err) } }); @@ -440,9 +439,7 @@ export class MysqlDriver extends AbstractDriver { resolve(true) } else { - console.error(`Error connecting to ${this.EngineName} Server.`) - console.error(err.message) - process.abort() + TomgUtils.LogFatalError(`Error connecting to ${this.EngineName} Server.`,false,err.message) reject(err) } }); @@ -480,4 +477,4 @@ export class MysqlDriver extends AbstractDriver { await promise; return ret; } -} \ No newline at end of file +} diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 81bdb82..73ee5b5 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -5,6 +5,7 @@ import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' import {promisify} from 'util' import { request } from 'https'; +import * as TomgUtils from './../Utils' /** @@ -17,19 +18,18 @@ import { request } from 'https'; try { this.Oracle= require('oracledb') } catch (error) { - console.error(error); - process.abort(); - throw error; - } - + TomgUtils.LogFatalError('',false,error); + throw error; + } + } - + FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - console.error(`Table ${entity.EntityName} has no PK.`) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) return; } entity.Columns.forEach(col => { @@ -37,12 +37,12 @@ import { request } from 'https'; }) }); } - - - + + + async GetAllTables(schema: string): Promise { - + let response :any[][] = ( await this.Connection.execute(` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`)).rows!; let ret: EntityInfo[] = []; response.forEach((val) => { @@ -58,7 +58,7 @@ import { request } from 'https'; let response :any[][] = ( await this.Connection.execute(`SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, IDENTITY_COLUMN FROM USER_TAB_COLUMNS`)).rows!; - + entities.forEach((ent) => { response.filter((filterVal) => { return filterVal[0] == ent.EntityName; @@ -80,7 +80,7 @@ import { request } from 'https'; colInfo.char_max_lenght = resp[5] > 0 ? resp[5] : null; break; default: - console.error("Unknown column type:" + resp[4]); + TomgUtils.LogFatalError("Unknown column type:" + resp[4]); break; } @@ -95,7 +95,7 @@ import { request } from 'https'; JOIN USER_IND_COLUMNS col ON ind.INDEX_NAME=col.INDEX_NAME LEFT JOIN USER_CONSTRAINTS uc ON uc.INDEX_NAME = ind.INDEX_NAME ORDER BY col.INDEX_NAME ASC ,col.COLUMN_POSITION ASC`)).rows!; - + entities.forEach((ent) => { response.filter((filterVal) => { return filterVal[0] == ent.EntityName; @@ -130,12 +130,12 @@ import { request } from 'https'; child.TABLE_NAME,childCol.COLUMN_NAME, owner.DELETE_RULE, 4,owner.CONSTRAINT_NAME - from user_constraints owner + from user_constraints owner join user_constraints child on owner.r_constraint_name=child.CONSTRAINT_NAME and child.constraint_type in ('P','U') JOIN USER_CONS_COLUMNS ownCol ON owner.CONSTRAINT_NAME = ownCol.CONSTRAINT_NAME JOIN USER_CONS_COLUMNS childCol ON child.CONSTRAINT_NAME = childCol.CONSTRAINT_NAME AND ownCol.POSITION=childCol.POSITION ORDER BY ownTbl ASC, owner.CONSTRAINT_NAME ASC, ownCol.POSITION ASC`)).rows!; - + let relationsTemp: RelationTempInfo[] = []; response.forEach((resp) => { @@ -161,28 +161,28 @@ import { request } from 'https'; return entitity.EntityName == relationTmp.ownerTable; }) if (!ownerEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) return; } let referencedEntity = entities.find((entitity) => { return entitity.EntityName == relationTmp.referencedTable; }) if (!referencedEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) return; } let ownerColumn = ownerEntity.Columns.find((column) => { return column.name == relationTmp.ownerColumnsNames[0]; }) if (!ownerColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) return; } let relatedColumn = referencedEntity.Columns.find((column) => { return column.name == relationTmp.referencedColumnsNames[0]; }) if (!relatedColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) return; } let ownColumn: ColumnInfo = ownerColumn; @@ -282,9 +282,7 @@ import { request } from 'https'; resolve(true) } else { - console.error('Error connecting to Oracle Server.') - console.error(err.message) - process.abort() + TomgUtils.LogFatalError('Error connecting to Oracle Server.',false,err.message) reject(err) } @@ -294,7 +292,7 @@ import { request } from 'https'; await promise; } - + async CreateDB(dbName: string) { } @@ -305,4 +303,4 @@ import { request } from 'https'; async CheckIfDBExists(dbName: string): Promise { return true; } -} \ No newline at end of file +} diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index f1d7176..f3bc2ed 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -4,6 +4,7 @@ import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' +import * as TomgUtils from './../Utils' /** * PostgresDriver */ @@ -14,7 +15,7 @@ export class PostgresDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - console.error(`Table ${entity.EntityName} has no PK.`) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) return; } entity.Columns.forEach(col => { @@ -205,7 +206,7 @@ export class PostgresDriver extends AbstractDriver { break; default: - console.error("Unknown column type:" + resp.data_type); + TomgUtils.LogFatalError("Unknown column type:" + resp.data_type); break; } @@ -348,28 +349,28 @@ export class PostgresDriver extends AbstractDriver { return entitity.EntityName == relationTmp.ownerTable; }) if (!ownerEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.ownerTable}.`) return; } let referencedEntity = entities.find((entitity) => { return entitity.EntityName == relationTmp.referencedTable; }) if (!referencedEntity) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity model ${relationTmp.referencedTable}.`) return; } let ownerColumn = ownerEntity.Columns.find((column) => { return column.name == relationTmp.ownerColumnsNames[0]; }) if (!ownerColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.ownerTable}.${ownerColumn}.`) return; } let relatedColumn = referencedEntity.Columns.find((column) => { return column.name == relationTmp.referencedColumnsNames[0]; }) if (!relatedColumn) { - console.error(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) + TomgUtils.LogFatalError(`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} didn't found entity column ${relationTmp.referencedTable}.${relatedColumn}.`) return; } let ownColumn: ColumnInfo = ownerColumn; @@ -451,9 +452,7 @@ export class PostgresDriver extends AbstractDriver { resolve(true) } else { - console.error('Error connecting to Postgres Server.') - console.error(err.message) - process.abort() + TomgUtils.LogFatalError('Error connecting to Postgres Server.',false,err.message) reject(err) } }); @@ -481,9 +480,7 @@ export class PostgresDriver extends AbstractDriver { resolve(true) } else { - console.error('Error connecting to Postgres Server.') - console.error(err.message) - process.abort() + TomgUtils.LogFatalError('Error connecting to Postgres Server.',false,err.message) reject(err) } }); @@ -507,4 +504,4 @@ export class PostgresDriver extends AbstractDriver { let resp = await this.Connection.query(`SELECT datname FROM pg_database WHERE datname ='${dbName}' `) return resp.rowCount > 0; } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 5e3638b..4cb9518 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { MariaDbDriver } from "./drivers/MariaDbDriver"; import { OracleDriver } from "./drivers/OracleDriver"; import { Engine } from './Engine' import * as Yargs from 'yargs' +import * as TomgUtils from './Utils' import path = require('path') @@ -39,7 +40,7 @@ var argv = Yargs .option('e', { alias: 'engine', describe: 'Database engine.', - choices: ['mssql', 'postgres', 'mysql', 'mariadb','oracle'], + choices: ['mssql', 'postgres', 'mysql', 'mariadb', 'oracle'], default: 'mssql' }) .option('o', { @@ -51,9 +52,9 @@ var argv = Yargs alias: 'schema', describe: 'Schema name to create model from. Only for mssql and postgres.' }) - .option('ssl',{ - boolean:true, - default:false + .option('ssl', { + boolean: true, + default: false }) .argv; @@ -76,7 +77,7 @@ switch (argv.e) { driver = new MysqlDriver(); standardPort = 3306; break; - case 'mariadb': + case 'mariadb': driver = new MysqlDriver(); standardPort = 3306; break; @@ -85,8 +86,7 @@ switch (argv.e) { standardPort = 1521; break; default: - console.error('Database engine not recognized.') - process.abort(); + TomgUtils.LogFatalError('Database engine not recognized.',false) throw new Error('Database engine not recognized.'); } @@ -100,7 +100,7 @@ let engine = new Engine( databaseType: argv.e, resultsPath: argv.o, schemaName: argv.s || standardSchema, - ssl:argv.ssl + ssl: argv.ssl }); console.log(`[${new Date().toLocaleTimeString()}] Starting creation of model classes.`); diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 0000000..4b3471f --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1,4 @@ +declare module "*.json" { + const value: any; + export default value; +} From fe17e484cee886c91c5987719924cb953e31ac5f Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 31 Dec 2017 17:28:41 +0100 Subject: [PATCH 14/21] Formatting existing code --- .travis.yml | 52 ++++++++++--------- codecov.yml | 20 +++---- docker-compose.yml | 1 - src/Engine.ts | 14 ++--- src/Utils.ts | 8 +-- src/drivers/AbstractDriver.ts | 22 ++++---- src/drivers/MariaDbDriver.ts | 6 +-- src/drivers/MssqlDriver.ts | 14 ++--- src/drivers/MysqlDriver.ts | 8 +-- src/drivers/OracleDriver.ts | 34 ++++++------ src/drivers/PostgresDriver.ts | 16 +++--- src/index.ts | 3 +- src/models/ColumnInfo.ts | 2 - src/models/DatabaseModel.ts | 16 +++--- src/models/EntityInfo.ts | 34 ++++++------ src/models/IndexColumnInfo.ts | 6 +-- src/models/IndexInfo.ts | 8 +-- src/models/RelationInfo.ts | 5 +- src/models/RelationTempInfo.ts | 18 +++---- test/drivers/MssqlDriver.test.ts | 40 +++++++------- .../entityTypes/mariadb/entity/Post.ts | 2 +- .../entityTypes/mssql/entity/Post.ts | 2 +- .../entityTypes/mysql/entity/Post.ts | 2 +- .../entityTypes/postgres/entity/Post.ts | 2 +- .../sample1-simple-entity/entity/Post.ts | 4 +- .../entity/EverythingEntity.ts | 4 +- .../examples/sample16-indexes/entity/Post.ts | 8 +-- .../sample17-versioning/entity/Post.ts | 6 +-- .../sample2-one-to-one/entity/Post.ts | 4 +- .../sample2-one-to-one/entity/PostAuthor.ts | 6 +-- .../sample2-one-to-one/entity/PostCategory.ts | 4 +- .../sample2-one-to-one/entity/PostDetails.ts | 2 +- .../sample2-one-to-one/entity/PostImage.ts | 6 +-- .../entity/PostInformation.ts | 2 +- .../sample2-one-to-one/entity/PostMetadata.ts | 6 +-- .../entity/Post.ts | 4 +- .../sample3-many-to-one/entity/Post.ts | 4 +- .../sample3-many-to-one/entity/PostAuthor.ts | 4 +- .../entity/PostCategory.ts | 2 +- .../sample3-many-to-one/entity/PostDetails.ts | 2 +- .../sample3-many-to-one/entity/PostImage.ts | 2 +- .../entity/PostInformation.ts | 2 +- .../entity/PostMetadata.ts | 4 +- .../github-issues/12/entity/Post.ts | 2 +- .../github-issues/12/entity/PostAuthor.ts | 2 +- test/integration/integration.test.ts | 4 +- test/utils/EntityFileToJson.ts | 20 +++---- test/utils/GeneralTestUtils.ts | 2 +- tsconfig.json | 5 +- typings.json | 16 +++--- 50 files changed, 232 insertions(+), 230 deletions(-) diff --git a/.travis.yml b/.travis.yml index dae660a..1b05f74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,36 @@ language: node_js node_js: -- stable -- 8 -- 6 + - stable + - 8 + - 6 sudo: required services: -- docker + - docker env: - matrix: - - POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 POSTGRES_Username=postgres - POSTGRES_Password=!Passw0rd POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 - MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root MYSQL_Password=!Passw0rd - MYSQL_Database=typeorm_mg MYSQL_SSL=1 MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 - MARIADB_Username=root MARIADB_Password=!Passw0rd MARIADB_Database=typeorm_mg MARIADB_SSL=0 - global: - secure: Xj6wO8aghAhi6nvBI/HTtW9mIq9xfigIQfCC7ZkgAcqS4Oe3ba+7A5pCJq6Fxndadc6Bg1bZ3BGCH3Upf/Yv3zCFybsk43LwwXPJoG9gCrva/me7Sd+ws30EcD2dsKbvjZqNYai/XdrhzJY+KlxWvS/g3N/puBNffcU5hteo1zllxakQIAiavJ64D4g+Th8LSytmb2qDDToSsCxXkzNSutaKgZSf6T8QCWzcl0NCZkl69s9kX7L5335HVBD9lR/EKFC4wqHQjryCDRAyNRvItZRNlTPqgOI8lvcTsH9zKozDwEz7h/zcLebbY/+YTsLB5pb2sa62tkQE0x24TG7bLxujQShEQZU8itkRSV+w6+0JpBHQPlSUppkQJBNGKao7GaO/Eix4mSyvHkeECmTWDtEpBGWERYLqCKGe2Nj3BfcA2Ue6pjz9CX8wnrCbx53j6be3M/g/gcx7fbJbX3P95yc1CWAaR+tJKlP38rTcyo+o+Db1Ft0pzRJyZGmkGGPnCj6LxWYSmVqumLYDyqAMBDcQYuVwaKaTsJtU/2OBb3+zjKmWivV+19SXBqILvFbLv9IYLavpMr9OAwDGcJu0+mF+VCjGkZTlBxWJ53PmCoIJ6Qx/5o67LsCYL4L/hugNETlOEEKwe/k1mBraYWB0jI3mBUCV0d8J5P+ZQhwIZo4= + matrix: + - >- + POSTGRES_Skip=0 POSTGRES_Host=localhost POSTGRES_Port=5432 + POSTGRES_Username=postgres POSTGRES_Password=!Passw0rd + POSTGRES_Database=typeorm_mg POSTGRES_SSL=0 MYSQL_Skip=0 + MYSQL_Host=localhost MYSQL_Port=3306 MYSQL_Username=root + MYSQL_Password=!Passw0rd MYSQL_Database=typeorm_mg MYSQL_SSL=1 + MARIADB_Skip=0 MARIADB_Host=localhost MARIADB_Port=3307 + MARIADB_Username=root MARIADB_Password=!Passw0rd + MARIADB_Database=typeorm_mg MARIADB_SSL=0 + global: + secure: >- + Xj6wO8aghAhi6nvBI/HTtW9mIq9xfigIQfCC7ZkgAcqS4Oe3ba+7A5pCJq6Fxndadc6Bg1bZ3BGCH3Upf/Yv3zCFybsk43LwwXPJoG9gCrva/me7Sd+ws30EcD2dsKbvjZqNYai/XdrhzJY+KlxWvS/g3N/puBNffcU5hteo1zllxakQIAiavJ64D4g+Th8LSytmb2qDDToSsCxXkzNSutaKgZSf6T8QCWzcl0NCZkl69s9kX7L5335HVBD9lR/EKFC4wqHQjryCDRAyNRvItZRNlTPqgOI8lvcTsH9zKozDwEz7h/zcLebbY/+YTsLB5pb2sa62tkQE0x24TG7bLxujQShEQZU8itkRSV+w6+0JpBHQPlSUppkQJBNGKao7GaO/Eix4mSyvHkeECmTWDtEpBGWERYLqCKGe2Nj3BfcA2Ue6pjz9CX8wnrCbx53j6be3M/g/gcx7fbJbX3P95yc1CWAaR+tJKlP38rTcyo+o+Db1Ft0pzRJyZGmkGGPnCj6LxWYSmVqumLYDyqAMBDcQYuVwaKaTsJtU/2OBb3+zjKmWivV+19SXBqILvFbLv9IYLavpMr9OAwDGcJu0+mF+VCjGkZTlBxWJ53PmCoIJ6Qx/5o67LsCYL4L/hugNETlOEEKwe/k1mBraYWB0jI3mBUCV0d8J5P+ZQhwIZo4= before_install: - - sudo service mysql stop - - sudo service postgresql stop - - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" - - docker-compose up -d - - npm install -g npm@5 - - npm install -g greenkeeper-lockfile@1 - + - sudo service mysql stop + - sudo service postgresql stop + - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" + - docker-compose up -d + - npm install -g npm@5 + - npm install -g greenkeeper-lockfile@1 before_script: -- greenkeeper-lockfile-update -- npm run typings-install -- npm link typescript -- tsc + - greenkeeper-lockfile-update + - npm run typings-install + - npm link typescript + - tsc after_script: -- greenkeeper-lockfile-upload + - greenkeeper-lockfile-upload diff --git a/codecov.yml b/codecov.yml index 176f14b..d87b44e 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,14 +1,14 @@ parsers: - javascript: - enable_partials: yes + javascript: + enable_partials: yes comment: - layout: diff - behavior: default + layout: diff + behavior: default codecov: - notify: - require_ci_to_pass: no + notify: + require_ci_to_pass: no coverage: - status: - project: - default: - threshold: 5% + status: + project: + default: + threshold: 5% diff --git a/docker-compose.yml b/docker-compose.yml index 5884c91..cf9b21c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,4 +47,3 @@ services: # environment: # DB_SID: "ORCLCDB" # SYS_PASSWORD: "Oradoc_db1" - \ No newline at end of file diff --git a/src/Engine.ts b/src/Engine.ts index f2f8d2d..4817c7c 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -16,12 +16,12 @@ export class Engine { if (dbModel.entities.length > 0) { this.createModelFromMetadata(dbModel); } else { - TomgUtils.LogFatalError('Tables not found in selected database. Skipping creation of typeorm model.',false); + TomgUtils.LogFatalError('Tables not found in selected database. Skipping creation of typeorm model.', false); } return true; } - private async getEntitiesInfo(database: string, server: string, port: number, user: string, password: string, schemaName:string, ssl:boolean): Promise { - return await this.driver.GetDataFromServer(database, server, port, user, password,schemaName,ssl) + private async getEntitiesInfo(database: string, server: string, port: number, user: string, password: string, schemaName: string, ssl: boolean): Promise { + return await this.driver.GetDataFromServer(database, server, port, user, password, schemaName, ssl) } private createModelFromMetadata(databaseModel: DatabaseModel) { @@ -38,10 +38,10 @@ export class Engine { }); if (!fs.existsSync(entitesPath)) fs.mkdirSync(entitesPath); - let compliedTemplate = Handlebars.compile(template,{noEscape:true}) + let compliedTemplate = Handlebars.compile(template, { noEscape: true }) databaseModel.entities.forEach(element => { let resultFilePath = path.resolve(entitesPath, element.EntityName + '.ts'); - let rendered =compliedTemplate(element) + let rendered = compliedTemplate(element) fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' }) }); } @@ -83,6 +83,6 @@ export interface EngineOptions { password: string, resultsPath: string, databaseType: string, - schemaName:string, - ssl:boolean + schemaName: string, + ssl: boolean } diff --git a/src/Utils.ts b/src/Utils.ts index ae1b70d..3d34d96 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,12 +1,12 @@ import * as data from './../../package.json' -export function LogFatalError(errText:string, isABug:boolean=true,errObject?:any) { -let x = data; +export function LogFatalError(errText: string, isABug: boolean = true, errObject?: any) { + let x = data; console.error(`Fatal error occured.`) console.error(`${x.name}@${x.version} node@${process.version}`) console.error(`Fatal error occured in typeorm-model-generator.`) console.error(`If this is a bug please open an issue including this log on ${x.bugs.url}`) - if (isABug&&!errObject) errObject=new Error().stack - if (!!errObject) console.error(errObject) + if (isABug && !errObject) errObject = new Error().stack + if (!!errObject) console.error(errObject) process.abort() } diff --git a/src/drivers/AbstractDriver.ts b/src/drivers/AbstractDriver.ts index 707a86c..a63850c 100644 --- a/src/drivers/AbstractDriver.ts +++ b/src/drivers/AbstractDriver.ts @@ -4,22 +4,22 @@ import { DatabaseModel } from './../models/DatabaseModel' * AbstractDriver */ export abstract class AbstractDriver { - async GetDataFromServer(database: string, server: string, port: number, user: string, password: string, schema:string, ssl:boolean): Promise { + async GetDataFromServer(database: string, server: string, port: number, user: string, password: string, schema: string, ssl: boolean): Promise { let dbModel = {}; - await this.ConnectToServer(database, server, port, user, password,ssl); + await this.ConnectToServer(database, server, port, user, password, ssl); dbModel.entities = await this.GetAllTables(schema); - await this.GetCoulmnsFromEntity(dbModel.entities,schema); - await this.GetIndexesFromEntity(dbModel.entities,schema); - dbModel.entities = await this.GetRelations(dbModel.entities,schema); + await this.GetCoulmnsFromEntity(dbModel.entities, schema); + await this.GetIndexesFromEntity(dbModel.entities, schema); + dbModel.entities = await this.GetRelations(dbModel.entities, schema); await this.DisconnectFromServer(); this.FindPrimaryColumnsFromIndexes(dbModel) return dbModel; } - abstract async ConnectToServer(database: string, server: string, port: number, user: string, password: string,ssl:boolean); - abstract async GetAllTables(schema:string): Promise - abstract async GetCoulmnsFromEntity(entities: EntityInfo[],schema:string): Promise; - abstract async GetIndexesFromEntity(entities: EntityInfo[],schema:string): Promise; - abstract async GetRelations(entities: EntityInfo[],schema:string): Promise; + abstract async ConnectToServer(database: string, server: string, port: number, user: string, password: string, ssl: boolean); + abstract async GetAllTables(schema: string): Promise + abstract async GetCoulmnsFromEntity(entities: EntityInfo[], schema: string): Promise; + abstract async GetIndexesFromEntity(entities: EntityInfo[], schema: string): Promise; + abstract async GetRelations(entities: EntityInfo[], schema: string): Promise; abstract async FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel); abstract async DisconnectFromServer(); @@ -27,4 +27,4 @@ export abstract class AbstractDriver { abstract async DropDB(dbName: string); abstract async UseDB(dbName: string); abstract async CheckIfDBExists(dbName: string): Promise; -} \ No newline at end of file +} diff --git a/src/drivers/MariaDbDriver.ts b/src/drivers/MariaDbDriver.ts index 3595d97..db75c97 100644 --- a/src/drivers/MariaDbDriver.ts +++ b/src/drivers/MariaDbDriver.ts @@ -9,6 +9,6 @@ import { MysqlDriver } from './MysqlDriver'; * MariaDb */ export class MariaDbDriver extends MysqlDriver { - readonly EngineName:string = 'MariaDb' - -} \ No newline at end of file + readonly EngineName: string = 'MariaDb' + +} diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index 06c8fe1..488beaf 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -14,7 +14,7 @@ export class MssqlDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`, false) return; } entity.Columns.forEach(col => { @@ -361,15 +361,15 @@ order by isOneToMany = false; } let ownerRelation = new RelationInfo() - let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; - }).length>0){ - for (let i=2;i<=ownerEntity.Columns.length;i++){ - columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')+i.toString(); + }).length > 0) { + for (let i = 2; i <= ownerEntity.Columns.length; i++) { + columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; - }).length==0) break; + }).length == 0) break; } } ownerRelation.actionOnDelete = relationTmp.actionOnDelete @@ -442,7 +442,7 @@ order by resolve(true) } else { - TomgUtils.LogFatalError('Error connecting to MSSQL Server.',false,err.message) + TomgUtils.LogFatalError('Error connecting to MSSQL Server.', false, err.message) reject(err) } }); diff --git a/src/drivers/MysqlDriver.ts b/src/drivers/MysqlDriver.ts index 92aca50..9e370c5 100644 --- a/src/drivers/MysqlDriver.ts +++ b/src/drivers/MysqlDriver.ts @@ -15,7 +15,7 @@ export class MysqlDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`, false) return; } entity.Columns.forEach(col => { @@ -334,7 +334,7 @@ export class MysqlDriver extends AbstractDriver { if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; }).length > 0) { - for (let i=2;i<=ownerEntity.Columns.length;i++){ + for (let i = 2; i <= ownerEntity.Columns.length; i++) { columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; @@ -392,7 +392,7 @@ export class MysqlDriver extends AbstractDriver { resolve(true) } else { - TomgUtils.LogFatalError(`Error disconnecting to ${this.EngineName} Server.`,false,err.message) + TomgUtils.LogFatalError(`Error disconnecting to ${this.EngineName} Server.`, false, err.message) reject(err) } }); @@ -439,7 +439,7 @@ export class MysqlDriver extends AbstractDriver { resolve(true) } else { - TomgUtils.LogFatalError(`Error connecting to ${this.EngineName} Server.`,false,err.message) + TomgUtils.LogFatalError(`Error connecting to ${this.EngineName} Server.`, false, err.message) reject(err) } }); diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 73ee5b5..b0f8d34 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -3,7 +3,7 @@ import { ColumnInfo } from './../models/ColumnInfo' import { EntityInfo } from './../models/EntityInfo' import { RelationInfo } from './../models/RelationInfo' import { DatabaseModel } from './../models/DatabaseModel' -import {promisify} from 'util' +import { promisify } from 'util' import { request } from 'https'; import * as TomgUtils from './../Utils' @@ -11,14 +11,14 @@ import * as TomgUtils from './../Utils' /** * OracleDriver */ - export class OracleDriver extends AbstractDriver { - Oracle:any; +export class OracleDriver extends AbstractDriver { + Oracle: any; constructor() { super(); try { - this.Oracle= require('oracledb') + this.Oracle = require('oracledb') } catch (error) { - TomgUtils.LogFatalError('',false,error); + TomgUtils.LogFatalError('', false, error); throw error; } @@ -29,7 +29,7 @@ import * as TomgUtils from './../Utils' dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`, false) return; } entity.Columns.forEach(col => { @@ -43,7 +43,7 @@ import * as TomgUtils from './../Utils' async GetAllTables(schema: string): Promise { - let response :any[][] = ( await this.Connection.execute(` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`)).rows!; + let response: any[][] = (await this.Connection.execute(` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`)).rows!; let ret: EntityInfo[] = []; response.forEach((val) => { let ent: EntityInfo = new EntityInfo(); @@ -55,11 +55,11 @@ import * as TomgUtils from './../Utils' return ret; } async GetCoulmnsFromEntity(entities: EntityInfo[], schema: string): Promise { - let response :any[][] = ( await this.Connection.execute(`SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH, + let response: any[][] = (await this.Connection.execute(`SELECT TABLE_NAME, COLUMN_NAME, DATA_DEFAULT, NULLABLE, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, IDENTITY_COLUMN FROM USER_TAB_COLUMNS`)).rows!; - entities.forEach((ent) => { + entities.forEach((ent) => { response.filter((filterVal) => { return filterVal[0] == ent.EntityName; }).forEach((resp) => { @@ -90,7 +90,7 @@ import * as TomgUtils from './../Utils' return entities; } async GetIndexesFromEntity(entities: EntityInfo[], schema: string): Promise { - let response :any[][] = ( await this.Connection.execute(`SELECT ind.TABLE_NAME, ind.INDEX_NAME, col.COLUMN_NAME,ind.UNIQUENESS, CASE WHEN uc.CONSTRAINT_NAME IS NULL THEN 0 ELSE 1 END + let response: any[][] = (await this.Connection.execute(`SELECT ind.TABLE_NAME, ind.INDEX_NAME, col.COLUMN_NAME,ind.UNIQUENESS, CASE WHEN uc.CONSTRAINT_NAME IS NULL THEN 0 ELSE 1 END FROM USER_INDEXES ind JOIN USER_IND_COLUMNS col ON ind.INDEX_NAME=col.INDEX_NAME LEFT JOIN USER_CONSTRAINTS uc ON uc.INDEX_NAME = ind.INDEX_NAME @@ -126,7 +126,7 @@ import * as TomgUtils from './../Utils' return entities; } async GetRelations(entities: EntityInfo[], schema: string): Promise { - let response :any[][] = ( await this.Connection.execute(`select owner.TABLE_NAME ownTbl,ownCol.POSITION,ownCol.COLUMN_NAME, + let response: any[][] = (await this.Connection.execute(`select owner.TABLE_NAME ownTbl,ownCol.POSITION,ownCol.COLUMN_NAME, child.TABLE_NAME,childCol.COLUMN_NAME, owner.DELETE_RULE, 4,owner.CONSTRAINT_NAME @@ -261,28 +261,28 @@ import * as TomgUtils from './../Utils' private Connection: any/*Oracle.IConnection*/; async ConnectToServer(database: string, server: string, port: number, user: string, password: string, ssl: boolean) { - let config: any/*Oracle.IConnectionAttributes*/ = { + let config: any/*Oracle.IConnectionAttributes*/ = { user: user, password: password, // connectString: `${server}:${port}/ORCLCDB.localdomain/${database}`, connectString: `${server}:${port}/${database}`, - externalAuth: ssl + externalAuth: ssl } - let that=this; + let that = this; let promise = new Promise( (resolve, reject) => { - this.Oracle.getConnection( + this.Oracle.getConnection( config, function (err, connection) { if (!err) { //Connection successfull - that.Connection=connection + that.Connection = connection resolve(true) } else { - TomgUtils.LogFatalError('Error connecting to Oracle Server.',false,err.message) + TomgUtils.LogFatalError('Error connecting to Oracle Server.', false, err.message) reject(err) } diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index f3bc2ed..d205d53 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -15,7 +15,7 @@ export class PostgresDriver extends AbstractDriver { dbModel.entities.forEach(entity => { let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); if (!primaryIndex) { - TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`,false) + TomgUtils.LogFatalError(`Table ${entity.EntityName} has no PK.`, false) return; } entity.Columns.forEach(col => { @@ -389,15 +389,15 @@ export class PostgresDriver extends AbstractDriver { isOneToMany = false; } let ownerRelation = new RelationInfo() - let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; - }).length>0){ - for (let i=2;i<=ownerEntity.Columns.length;i++){ - columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')+i.toString(); + }).length > 0) { + for (let i = 2; i <= ownerEntity.Columns.length; i++) { + columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString(); if (referencedEntity.Columns.filter((filterVal) => { return filterVal.name == columnName; - }).length==0) break; + }).length == 0) break; } } ownerRelation.actionOnDelete = relationTmp.actionOnDelete @@ -452,7 +452,7 @@ export class PostgresDriver extends AbstractDriver { resolve(true) } else { - TomgUtils.LogFatalError('Error connecting to Postgres Server.',false,err.message) + TomgUtils.LogFatalError('Error connecting to Postgres Server.', false, err.message) reject(err) } }); @@ -480,7 +480,7 @@ export class PostgresDriver extends AbstractDriver { resolve(true) } else { - TomgUtils.LogFatalError('Error connecting to Postgres Server.',false,err.message) + TomgUtils.LogFatalError('Error connecting to Postgres Server.', false, err.message) reject(err) } }); diff --git a/src/index.ts b/src/index.ts index 4cb9518..ca61eb8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,7 +86,7 @@ switch (argv.e) { standardPort = 1521; break; default: - TomgUtils.LogFatalError('Database engine not recognized.',false) + TomgUtils.LogFatalError('Database engine not recognized.', false) throw new Error('Database engine not recognized.'); } @@ -107,4 +107,3 @@ console.log(`[${new Date().toLocaleTimeString()}] Starting creation of model cla engine.createModelFromDatabase().then(() => { console.info(`[${new Date().toLocaleTimeString()}] Typeorm model classes created.`) }) - diff --git a/src/models/ColumnInfo.ts b/src/models/ColumnInfo.ts index 3c241c2..97997e5 100644 --- a/src/models/ColumnInfo.ts +++ b/src/models/ColumnInfo.ts @@ -22,5 +22,3 @@ export class ColumnInfo { } } - - diff --git a/src/models/DatabaseModel.ts b/src/models/DatabaseModel.ts index c05eaff..411534e 100644 --- a/src/models/DatabaseModel.ts +++ b/src/models/DatabaseModel.ts @@ -1,4 +1,4 @@ -import {EntityInfo} from './EntityInfo' +import { EntityInfo } from './EntityInfo' export class DatabaseModel { entities: EntityInfo[]; config: { @@ -6,11 +6,11 @@ export class DatabaseModel { cascadeUpdate: boolean, cascadeRemove: boolean, } - relationImports():any{ - let that=this; - return function(text, render) { - if ('l'!=render(text)) return `import {${render(text)}} from "./${render(text)}"` - else return ''; + relationImports(): any { + let that = this; + return function (text, render) { + if ('l' != render(text)) return `import {${render(text)}} from "./${render(text)}"` + else return ''; + } } - } -} \ No newline at end of file +} diff --git a/src/models/EntityInfo.ts b/src/models/EntityInfo.ts index 68c4a3a..f3fe230 100644 --- a/src/models/EntityInfo.ts +++ b/src/models/EntityInfo.ts @@ -8,23 +8,23 @@ export class EntityInfo { Indexes: IndexInfo[]; relationImports(): any { - var returnString = ""; - var imports: string[] = []; - this.Columns.forEach((column) => { - column.relations.forEach( - (relation) => { - if (this.EntityName!=relation.relatedTable) + var returnString = ""; + var imports: string[] = []; + this.Columns.forEach((column) => { + column.relations.forEach( + (relation) => { + if (this.EntityName != relation.relatedTable) imports.push(relation.relatedTable); - } - ) - }); - imports.filter(function (elem, index, self) { - return index == self.indexOf(elem); - }).forEach((imp)=>{ - returnString+=`import {${imp}} from './${imp}'\n` - }) + } + ) + }); + imports.filter(function (elem, index, self) { + return index == self.indexOf(elem); + }).forEach((imp) => { + returnString += `import {${imp}} from './${imp}'\n` + }) - return returnString; + return returnString; } - -} \ No newline at end of file + +} diff --git a/src/models/IndexColumnInfo.ts b/src/models/IndexColumnInfo.ts index 1d9e579..5513189 100644 --- a/src/models/IndexColumnInfo.ts +++ b/src/models/IndexColumnInfo.ts @@ -1,5 +1,5 @@ -interface IndexColumnInfo{ - name:string, +interface IndexColumnInfo { + name: string, //isDescending:boolean, // isIncludedColumn:boolean -} \ No newline at end of file +} diff --git a/src/models/IndexInfo.ts b/src/models/IndexInfo.ts index ea9b74a..3fc7540 100644 --- a/src/models/IndexInfo.ts +++ b/src/models/IndexInfo.ts @@ -2,8 +2,8 @@ * IndexInfo */ interface IndexInfo { - name:string, - columns:IndexColumnInfo[], - isUnique:boolean, - isPrimaryKey:boolean, + name: string, + columns: IndexColumnInfo[], + isUnique: boolean, + isPrimaryKey: boolean, } diff --git a/src/models/RelationInfo.ts b/src/models/RelationInfo.ts index eb7d0b7..f68ffce 100644 --- a/src/models/RelationInfo.ts +++ b/src/models/RelationInfo.ts @@ -1,4 +1,5 @@ -export class RelationInfo { [x: string]: any; +export class RelationInfo { + [x: string]: any; isOwner: boolean relationType: "OneToOne" | "OneToMany" | "ManyToOne" @@ -13,4 +14,4 @@ export class RelationInfo { [x: string]: any; return this.relationType == "OneToMany" } -} \ No newline at end of file +} diff --git a/src/models/RelationTempInfo.ts b/src/models/RelationTempInfo.ts index 0837f6e..94a82ec 100644 --- a/src/models/RelationTempInfo.ts +++ b/src/models/RelationTempInfo.ts @@ -1,9 +1,9 @@ -interface RelationTempInfo{ - ownerTable:string, - ownerColumnsNames:string[], - referencedTable:string, - referencedColumnsNames:string[], - actionOnDelete:"RESTRICT"|"CASCADE"|"SET NULL"|"NO ACTION", - actionOnUpdate:"RESTRICT"|"CASCADE"|"SET NULL"|"NO ACTION", - object_id:number|string -} \ No newline at end of file +interface RelationTempInfo { + ownerTable: string, + ownerColumnsNames: string[], + referencedTable: string, + referencedColumnsNames: string[], + actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION", + actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "NO ACTION", + object_id: number | string +} diff --git a/test/drivers/MssqlDriver.test.ts b/test/drivers/MssqlDriver.test.ts index bbcb22a..70a547f 100644 --- a/test/drivers/MssqlDriver.test.ts +++ b/test/drivers/MssqlDriver.test.ts @@ -7,19 +7,19 @@ import { ColumnInfo } from './../../src/models/ColumnInfo' import { RelationInfo } from './../../src/models/RelationInfo' import { Table, IColumnMetadata } from "mssql"; - class fakeResponse implements MSSQL.IResult { - recordsets: MSSQL.IRecordSet[]; - recordset: MSSQL.IRecordSet; - rowsAffected: number[]; - output: { [key: string]: any; }; - - } - class fakeRecordset extends Array implements MSSQL.IRecordSet{ +class fakeResponse implements MSSQL.IResult { + recordsets: MSSQL.IRecordSet[]; + recordset: MSSQL.IRecordSet; + rowsAffected: number[]; + output: { [key: string]: any; }; + +} +class fakeRecordset extends Array implements MSSQL.IRecordSet{ columns: IColumnMetadata; - toTable(): Table{ + toTable(): Table { return new Table(); } - } +} describe('MssqlDriver', function () { let driver: MssqlDriver @@ -48,10 +48,10 @@ describe('MssqlDriver', function () { .returns( { query: (q) => { - - let response=new fakeResponse(); - - response.recordset=new fakeRecordset(); + + let response = new fakeResponse(); + + response.recordset = new fakeRecordset(); response.recordset.push({ TABLE_SCHEMA: 'schema', TABLE_NAME: 'name' }) return response; } @@ -71,13 +71,13 @@ describe('MssqlDriver', function () { .returns( { query: (q) => { - let response=new fakeResponse(); - response.recordset=new fakeRecordset(); + let response = new fakeResponse(); + response.recordset = new fakeRecordset(); response.recordset.push({ TABLE_NAME: 'name', CHARACTER_MAXIMUM_LENGTH: 0, COLUMN_DEFAULT: 'a', COLUMN_NAME: 'name', DATA_TYPE: 'int', IS_NULLABLE: 'YES', NUMERIC_PRECISION: 0, NUMERIC_SCALE: 0, - IsIdentity:1 + IsIdentity: 1 }) return response; } @@ -97,7 +97,7 @@ describe('MssqlDriver', function () { default: 'a', is_nullable: true, isPrimary: false, - is_generated:true, + is_generated: true, name: 'name', numericPrecision: null, numericScale: null, @@ -105,10 +105,10 @@ describe('MssqlDriver', function () { ts_type: 'number', relations: [] }) - let result = await driver.GetCoulmnsFromEntity(entities,'schema'); + let result = await driver.GetCoulmnsFromEntity(entities, 'schema'); expect(result).to.be.deep.equal(expected) }) it('should find primary indexes') it('should get indexes info') it('should get relations info') -}) \ No newline at end of file +}) diff --git a/test/integration/entityTypes/mariadb/entity/Post.ts b/test/integration/entityTypes/mariadb/entity/Post.ts index 2b25f57..61d4028 100644 --- a/test/integration/entityTypes/mariadb/entity/Post.ts +++ b/test/integration/entityTypes/mariadb/entity/Post.ts @@ -91,4 +91,4 @@ export class Post { // @Column("simple-array") // simpleArray: string[]; -} \ No newline at end of file +} diff --git a/test/integration/entityTypes/mssql/entity/Post.ts b/test/integration/entityTypes/mssql/entity/Post.ts index 43b4c19..39311cf 100644 --- a/test/integration/entityTypes/mssql/entity/Post.ts +++ b/test/integration/entityTypes/mssql/entity/Post.ts @@ -118,4 +118,4 @@ export class Post { // @Column("simple-array") // simpleArray: string[]; -} \ No newline at end of file +} diff --git a/test/integration/entityTypes/mysql/entity/Post.ts b/test/integration/entityTypes/mysql/entity/Post.ts index 8149e01..16a217e 100644 --- a/test/integration/entityTypes/mysql/entity/Post.ts +++ b/test/integration/entityTypes/mysql/entity/Post.ts @@ -90,4 +90,4 @@ export class Post { // @Column("simple-array") // simpleArray: string[]; -} \ No newline at end of file +} diff --git a/test/integration/entityTypes/postgres/entity/Post.ts b/test/integration/entityTypes/postgres/entity/Post.ts index 9acf3ea..fb81185 100644 --- a/test/integration/entityTypes/postgres/entity/Post.ts +++ b/test/integration/entityTypes/postgres/entity/Post.ts @@ -237,4 +237,4 @@ export class Post { // @Column("simple-array") // simpleArray: string[]; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample1-simple-entity/entity/Post.ts b/test/integration/examples/sample1-simple-entity/entity/Post.ts index 6c208ff..acc4bc1 100644 --- a/test/integration/examples/sample1-simple-entity/entity/Post.ts +++ b/test/integration/examples/sample1-simple-entity/entity/Post.ts @@ -1,4 +1,4 @@ -import {Column, Entity,PrimaryGeneratedColumn,Index,Generated} from "typeorm"; +import { Column, Entity, PrimaryGeneratedColumn, Index, Generated } from "typeorm"; @Entity("Post") export class Post { @@ -17,4 +17,4 @@ export class Post { }) likesCount: number; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts b/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts index a2eb712..a627625 100644 --- a/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts +++ b/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts @@ -2,7 +2,7 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } f @Entity("EverythingEntity") export class EverythingEntity { - //TODO: change to check column types per database engine + //TODO: change to check column types per database engine @PrimaryGeneratedColumn() id: number; @@ -69,4 +69,4 @@ export class EverythingEntity { // @UpdateDateColumn() // updatedDate: Date; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample16-indexes/entity/Post.ts b/test/integration/examples/sample16-indexes/entity/Post.ts index 531fcfa..cf25a35 100644 --- a/test/integration/examples/sample16-indexes/entity/Post.ts +++ b/test/integration/examples/sample16-indexes/entity/Post.ts @@ -1,8 +1,8 @@ -import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm" +import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm" @Entity("Post") -@Index("my_index_with_id_and_text", ["id", "text"], {unique:true}) -@Index("my_index_with_id_and_title", (post: Post) => [post.id, post.title], {unique:true}) +@Index("my_index_with_id_and_text", ["id", "text"], { unique: true }) +@Index("my_index_with_id_and_title", (post: Post) => [post.id, post.title], { unique: true }) export class Post { @PrimaryGeneratedColumn() @@ -23,4 +23,4 @@ export class Post { @Index() likesCount: number; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample17-versioning/entity/Post.ts b/test/integration/examples/sample17-versioning/entity/Post.ts index 60b8d24..e9f1bc1 100644 --- a/test/integration/examples/sample17-versioning/entity/Post.ts +++ b/test/integration/examples/sample17-versioning/entity/Post.ts @@ -1,4 +1,4 @@ -import { Column, Entity, Index, PrimaryGeneratedColumn, VersionColumn } from "typeorm" +import { Column, Entity, Index, PrimaryGeneratedColumn, VersionColumn } from "typeorm" @Entity("Post") export class Post { @@ -14,5 +14,5 @@ export class Post { @VersionColumn() version: number; - -} \ No newline at end of file + +} diff --git a/test/integration/examples/sample2-one-to-one/entity/Post.ts b/test/integration/examples/sample2-one-to-one/entity/Post.ts index cec9818..f715c0a 100644 --- a/test/integration/examples/sample2-one-to-one/entity/Post.ts +++ b/test/integration/examples/sample2-one-to-one/entity/Post.ts @@ -27,7 +27,7 @@ export class Post { @Index({ unique: true }) category: PostCategory; - // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this + // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this // relation it will be inserted automatically to the db when you save this Post entity @OneToOne(type => PostDetails, details => details.post, { cascade: true @@ -69,4 +69,4 @@ export class Post { @Index({ unique: true }) author: PostAuthor; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostAuthor.ts b/test/integration/examples/sample2-one-to-one/entity/PostAuthor.ts index 9dfb66e..d80d803 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostAuthor.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostAuthor.ts @@ -1,5 +1,5 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; -import {Post} from "./Post"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; +import { Post } from "./Post"; @Entity("PostAuthor") export class PostAuthor { @@ -13,4 +13,4 @@ export class PostAuthor { @OneToOne(type => Post, post => post.author) post: Post; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostCategory.ts b/test/integration/examples/sample2-one-to-one/entity/PostCategory.ts index 6b302b0..c7b2311 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostCategory.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostCategory.ts @@ -1,4 +1,4 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; @Entity("PostCategory") export class PostCategory { @@ -9,4 +9,4 @@ export class PostCategory { @Column() name: string; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts index 917af60..b68e075 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostDetails.ts @@ -22,4 +22,4 @@ export class PostDetails { }) post: Post; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostImage.ts b/test/integration/examples/sample2-one-to-one/entity/PostImage.ts index afea4c8..6e71d4e 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostImage.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostImage.ts @@ -1,5 +1,5 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; -import {Post} from "./Post"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; +import { Post } from "./Post"; @Entity("PostImage") export class PostImage { @@ -13,4 +13,4 @@ export class PostImage { @OneToOne(type => Post, post => post.image) post: Post; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts b/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts index 0673ca4..f71ef43 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostInformation.ts @@ -13,4 +13,4 @@ export class PostInformation { @OneToOne(type => Post, post => post.information) post: Post; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample2-one-to-one/entity/PostMetadata.ts b/test/integration/examples/sample2-one-to-one/entity/PostMetadata.ts index c2f75d1..da7eee3 100644 --- a/test/integration/examples/sample2-one-to-one/entity/PostMetadata.ts +++ b/test/integration/examples/sample2-one-to-one/entity/PostMetadata.ts @@ -1,5 +1,5 @@ -import {PrimaryGeneratedColumn, Column, Entity, OneToOne,JoinColumn} from "typeorm"; -import {Post} from "./Post"; +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn } from "typeorm"; +import { Post } from "./Post"; @Entity("PostMetadata") export class PostMetadata { @@ -13,4 +13,4 @@ export class PostMetadata { @OneToOne(type => Post, post => post.metadata) post: Post; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample27-composite-primary-keys/entity/Post.ts b/test/integration/examples/sample27-composite-primary-keys/entity/Post.ts index 26d9d80..6e716e5 100644 --- a/test/integration/examples/sample27-composite-primary-keys/entity/Post.ts +++ b/test/integration/examples/sample27-composite-primary-keys/entity/Post.ts @@ -1,4 +1,4 @@ -import {Column, Entity, PrimaryColumn} from "typeorm"; +import { Column, Entity, PrimaryColumn } from "typeorm"; @Entity("Post") export class Post { @@ -12,4 +12,4 @@ export class Post { @Column() text: string; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/Post.ts b/test/integration/examples/sample3-many-to-one/entity/Post.ts index 36b60ea..4505194 100644 --- a/test/integration/examples/sample3-many-to-one/entity/Post.ts +++ b/test/integration/examples/sample3-many-to-one/entity/Post.ts @@ -25,7 +25,7 @@ export class Post { }) category: PostCategory; - // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this + // post has relation with details. cascade inserts here means if new PostDetails instance will be set to this // relation it will be inserted automatically to the db when you save this Post entity @ManyToOne(type => PostDetails, details => details.posts, { cascade: true, @@ -57,4 +57,4 @@ export class Post { @ManyToOne(type => PostAuthor, author => author.posts) author: PostAuthor; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostAuthor.ts b/test/integration/examples/sample3-many-to-one/entity/PostAuthor.ts index 90b0d38..bc8b77e 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostAuthor.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostAuthor.ts @@ -1,5 +1,5 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, OneToMany, ManyToOne, JoinColumn } from "typeorm"; -import {Post} from "./Post"; +import { Post } from "./Post"; @Entity("PostAuthor") export class PostAuthor { @@ -13,4 +13,4 @@ export class PostAuthor { @OneToMany(type => Post, post => post.author) posts: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostCategory.ts b/test/integration/examples/sample3-many-to-one/entity/PostCategory.ts index bae28e4..c92df8f 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostCategory.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostCategory.ts @@ -9,4 +9,4 @@ export class PostCategory { @Column() name: string; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts b/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts index 4cf9d2c..3c1a2f6 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostDetails.ts @@ -25,4 +25,4 @@ export class PostDetails { @OneToMany(type => Post, post => post.details) posts: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostImage.ts b/test/integration/examples/sample3-many-to-one/entity/PostImage.ts index 2965712..dad410d 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostImage.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostImage.ts @@ -13,4 +13,4 @@ export class PostImage { @OneToMany(type => Post, post => post.image) posts: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts b/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts index def7ca5..5e427e3 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostInformation.ts @@ -13,4 +13,4 @@ export class PostInformation { @OneToMany(type => Post, post => post.information) posts: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/examples/sample3-many-to-one/entity/PostMetadata.ts b/test/integration/examples/sample3-many-to-one/entity/PostMetadata.ts index ce724db..3b2fb19 100644 --- a/test/integration/examples/sample3-many-to-one/entity/PostMetadata.ts +++ b/test/integration/examples/sample3-many-to-one/entity/PostMetadata.ts @@ -1,5 +1,5 @@ import { PrimaryGeneratedColumn, Column, Entity, OneToOne, OneToMany, ManyToOne, JoinColumn } from "typeorm"; -import {Post} from "./Post"; +import { Post } from "./Post"; @Entity("PostMetadata") export class PostMetadata { @@ -13,4 +13,4 @@ export class PostMetadata { @OneToMany(type => Post, post => post.metadata) posts: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/github-issues/12/entity/Post.ts b/test/integration/github-issues/12/entity/Post.ts index 79d2472..3a94f13 100644 --- a/test/integration/github-issues/12/entity/Post.ts +++ b/test/integration/github-issues/12/entity/Post.ts @@ -13,4 +13,4 @@ export class Post { @ManyToOne(type => PostAuthor, author => author.posts2) author2: PostAuthor; -} \ No newline at end of file +} diff --git a/test/integration/github-issues/12/entity/PostAuthor.ts b/test/integration/github-issues/12/entity/PostAuthor.ts index 9d5a433..d203269 100644 --- a/test/integration/github-issues/12/entity/PostAuthor.ts +++ b/test/integration/github-issues/12/entity/PostAuthor.ts @@ -13,4 +13,4 @@ export class PostAuthor { @OneToMany(type => Post, post => post.author2) posts2: Post[]; -} \ No newline at end of file +} diff --git a/test/integration/integration.test.ts b/test/integration/integration.test.ts index fe0619b..fe7c24f 100644 --- a/test/integration/integration.test.ts +++ b/test/integration/integration.test.ts @@ -53,10 +53,10 @@ describe("TypeOrm examples", async function () { case 'mysql': engine = await GTU.createMysqlModels(filesOrgPathJS, resultsPath) break; - case 'mariadb': + case 'mariadb': engine = await GTU.createMariaDBModels(filesOrgPathJS, resultsPath) break; - case 'oracle': + case 'oracle': engine = await GTU.createOracleDBModels(filesOrgPathJS, resultsPath) break; diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index 9ea6b4f..22f9a42 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -21,7 +21,7 @@ export class EntityFileToJson { // if (!x.endsWith('[]')) { // x = x + '[]'// can't distinguish OneTwoMany from OneToOne without indexes // } - x=x.trim(); + x = x.trim(); return x; }); } else { @@ -93,7 +93,7 @@ export class EntityFileToJson { for (let line of lines) { let trimmedLine = line.trim(); if (trimmedLine.startsWith('//')) { - continue; //commented line + continue; //commented line } if (isMultilineStatement) trimmedLine = priorPartOfMultilineStatement + ' ' + trimmedLine @@ -102,7 +102,7 @@ export class EntityFileToJson { else if (!isInClassBody) { if (trimmedLine.startsWith('import')) { - continue; //import statement is not part of entity definition + continue; //import statement is not part of entity definition } else if (trimmedLine.startsWith('@Entity')) { continue; //TODO:entity options } else if (trimmedLine.startsWith('export class')) { @@ -244,7 +244,7 @@ export class EntityFileToJson { // if (!x.endsWith('[]')) { // x = x + '[]'// can't distinguish OneTwoMany from OneToOne without indexes // } - x=x.trim(); + x = x.trim(); return x; }); @@ -274,15 +274,15 @@ export class EntityFileToJson { console.log(`${trimmedLine}`) } - retVal.columns=retVal.columns.map(col=>{ + retVal.columns = retVal.columns.map(col => { if (col.columnName.endsWith('Id')) - col.columnName=col.columnName.substr(0,col.columnName.length-2) + col.columnName = col.columnName.substr(0, col.columnName.length - 2) return col; }) - retVal.indicies=retVal.indicies.map(ind=>{ - ind.columnNames=ind.columnNames.map(colName=>{ + retVal.indicies = retVal.indicies.map(ind => { + ind.columnNames = ind.columnNames.map(colName => { if (colName.endsWith('Id')) - colName=colName.substr(0,colName.length-2) + colName = colName.substr(0, colName.length - 2) return colName; }) return ind; @@ -314,4 +314,4 @@ class EntityIndex { indexName: string columnNames: string[] = [] isUnique: boolean = false -} \ No newline at end of file +} diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 65e5fdb..68a88ad 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -250,4 +250,4 @@ export function compileTsFiles(fileNames: string[], options: ts.CompilerOptions) }); return compileErrors; -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 09773a7..d8e44e0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,8 +14,9 @@ "moduleResolution": "node", "outDir": "dist", "newLine": "LF" - }, "include": [ + }, + "include": [ "src", "test" ] -} \ No newline at end of file +} diff --git a/typings.json b/typings.json index 82bf57c..91fce6a 100644 --- a/typings.json +++ b/typings.json @@ -1,10 +1,10 @@ { - "globalDevDependencies": { - "mustache": "registry:dt/mustache#0.8.2+20160510002910" - }, - "dependencies": { - "mssql": "registry:dt/mssql#3.3.0+20170311011547", - "yargs": "registry:npm/yargs#5.0.0+20160907000723", - "yn": "registry:npm/yn#1.3.0+20170508185912" - } + "globalDevDependencies": { + "mustache": "registry:dt/mustache#0.8.2+20160510002910" + }, + "dependencies": { + "mssql": "registry:dt/mssql#3.3.0+20170311011547", + "yargs": "registry:npm/yargs#5.0.0+20160907000723", + "yn": "registry:npm/yn#1.3.0+20170508185912" + } } From 775a398ed9b36551b1f678dc4ec31f15aa4d8013 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Fri, 5 Jan 2018 22:34:10 +0100 Subject: [PATCH 15/21] fixing #13 --- src/entity.mst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/entity.mst b/src/entity.mst index eef4c55..bea2940 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -15,14 +15,14 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi default:"{{.}}",{{/default}}{{#numericPrecision}} precision:{{.}},{{/numericPrecision}}{{#numericScale}} scale:{{.}},{{/numericScale}}{{#isPrimary}} - primary:{{isPrimary}},{{/isPrimary}} + primary:{{isPrimary}},{{/isPrimary}} }) {{name}}:{{ts_type}}; {{/relations}}{{#relations}} @{{relationType}}(type=>{{relatedTable}}, {{../name}}=>{{../name}}.{{#if isOwner}}{{ownerColumn}}{{else}}{{relatedColumn}}{{/if}}){{#isOwner}} - @JoinColumn(){{/isOwner}} + @JoinColumn({name:'{{../name}}'}){{/isOwner}} {{#if isOneToMany}}{{../name}}:{{relatedTable}}[]; {{else}}{{../name}}:{{relatedTable}}; {{/if}}{{/relations}} {{/Columns}} -} \ No newline at end of file +} From f62795c75de20905d6e1f78cc51b6f8fdd1019e7 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 11 Jan 2018 20:27:47 +0000 Subject: [PATCH 16/21] chore(package): update remap-istanbul to version 0.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 614b206..7fdb92f 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "fs-extra": "^5.0.0", "istanbul": "^0.4.5", "mocha": "^4.0.1", - "remap-istanbul": "^0.9.5", + "remap-istanbul": "^0.10.0", "sinon": "^4.1.2", "sinon-chai": "^2.14.0", "typings": "^2.1.1" From e5bcd9a7c25ac4b8c1c005091c6dee0ea4a92ce5 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 11 Jan 2018 20:31:04 +0000 Subject: [PATCH 17/21] chore(package): update lockfile https://npm.im/greenkeeper-lockfile --- package-lock.json | 526 ++++++++-------------------------------------- 1 file changed, 86 insertions(+), 440 deletions(-) diff --git a/package-lock.json b/package-lock.json index e68bc73..70c2a3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -181,12 +181,30 @@ } } }, + "ansi-cyan": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ansi-cyan/-/ansi-cyan-0.1.1.tgz", + "integrity": "sha1-U4rlKK+JgvKK4w2G8vF0VtJgmHM=", + "dev": true, + "requires": { + "ansi-wrap": "0.1.0" + } + }, "ansi-escapes": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz", "integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4=", "dev": true }, + "ansi-red": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ansi-red/-/ansi-red-0.1.1.tgz", + "integrity": "sha1-jGOPnRCAgAo1PJwoyKgcpHBdlGw=", + "dev": true, + "requires": { + "ansi-wrap": "0.1.0" + } + }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -197,6 +215,12 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" }, + "ansi-wrap": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz", + "integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768=", + "dev": true + }, "any-promise": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", @@ -227,16 +251,32 @@ "integrity": "sha1-7L0W+JSbFXGDcRsb2jNPN4QBhas=", "dev": true }, - "array-differ": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/array-differ/-/array-differ-1.0.0.tgz", - "integrity": "sha1-7/UuN1gknTO+QCuLuOVkuytdQDE=", + "arr-diff": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-1.1.0.tgz", + "integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=", + "dev": true, + "requires": { + "arr-flatten": "1.1.0", + "array-slice": "0.2.3" + } + }, + "arr-flatten": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz", + "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==", "dev": true }, - "array-find-index": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/array-find-index/-/array-find-index-1.0.2.tgz", - "integrity": "sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E=", + "arr-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", + "integrity": "sha1-IPnqtexw9cfSFbEHexw5Fh0pLH0=", + "dev": true + }, + "array-slice": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz", + "integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=", "dev": true }, "array-uniq": { @@ -310,12 +350,6 @@ "tweetnacl": "0.14.5" } }, - "beeper": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/beeper/-/beeper-1.1.1.tgz", - "integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=", - "dev": true - }, "big-number": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/big-number/-/big-number-0.3.1.tgz", @@ -419,24 +453,6 @@ "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", "optional": true }, - "camelcase-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-2.1.0.tgz", - "integrity": "sha1-MIvur/3ygRkFHvodkyITyRuPkuc=", - "dev": true, - "requires": { - "camelcase": "2.1.1", - "map-obj": "1.0.1" - }, - "dependencies": { - "camelcase": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", - "integrity": "sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8=", - "dev": true - } - } - }, "capture-stack-trace": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/capture-stack-trace/-/capture-stack-trace-1.0.0.tgz", @@ -641,12 +657,6 @@ "integrity": "sha1-Jgt6meux7f4kdTgXX3gyQ8sZ0Uk=", "dev": true }, - "clone-stats": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz", - "integrity": "sha1-uI+UqCzzi4eR1YBG6kAprYjKmdE=", - "dev": true - }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -785,15 +795,6 @@ "integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=", "dev": true }, - "currently-unhandled": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", - "integrity": "sha1-mI3zP+qxke95mmE2nddsF635V+o=", - "dev": true, - "requires": { - "array-find-index": "1.0.2" - } - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -811,16 +812,6 @@ } } }, - "dateformat": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-1.0.12.tgz", - "integrity": "sha1-nxJLZ1lMk3/3BpMuSmQsyo27/uk=", - "dev": true, - "requires": { - "get-stdin": "4.0.1", - "meow": "3.7.0" - } - }, "debug": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.0.tgz", @@ -888,41 +879,6 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-4.0.0.tgz", "integrity": "sha1-hk7xN5rO1Vzm+V3r7NzhefegzR0=" }, - "duplexer2": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.0.2.tgz", - "integrity": "sha1-xhTc9n4vsUmVqRcR5aYX6KYKMds=", - "dev": true, - "requires": { - "readable-stream": "1.1.14" - }, - "dependencies": { - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "dev": true - }, - "readable-stream": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", - "dev": true, - "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "0.0.1", - "string_decoder": "0.10.31" - } - }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true - } - } - }, "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", @@ -1035,22 +991,29 @@ "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=", "dev": true }, + "extend-shallow": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", + "integrity": "sha1-Gda/lN/AnXa6cR85uHLSH/TdkHE=", + "dev": true, + "requires": { + "kind-of": "1.1.0" + }, + "dependencies": { + "kind-of": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", + "dev": true + } + } + }, "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", "dev": true }, - "fancy-log": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-1.3.0.tgz", - "integrity": "sha1-Rb4X0Cu5kX1gzP/UmVyZnmyMmUg=", - "dev": true, - "requires": { - "chalk": "1.1.3", - "time-stamp": "1.1.0" - } - }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", @@ -1135,12 +1098,6 @@ "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", "dev": true }, - "get-stdin": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz", - "integrity": "sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4=", - "dev": true - }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", @@ -1176,15 +1133,6 @@ "path-is-absolute": "1.0.1" } }, - "glogg": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/glogg/-/glogg-1.0.0.tgz", - "integrity": "sha1-f+DxmfV6yQbPUS/urY+Q7kooT8U=", - "dev": true, - "requires": { - "sparkles": "1.0.0" - } - }, "got": { "version": "6.7.1", "resolved": "https://registry.npmjs.org/got/-/got-6.7.1.tgz", @@ -1209,49 +1157,6 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, - "gulp-util": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/gulp-util/-/gulp-util-3.0.7.tgz", - "integrity": "sha1-eJJcS4+LSQBawBoBHFV+YhiUHLs=", - "dev": true, - "requires": { - "array-differ": "1.0.0", - "array-uniq": "1.0.3", - "beeper": "1.1.1", - "chalk": "1.1.3", - "dateformat": "1.0.12", - "fancy-log": "1.3.0", - "gulplog": "1.0.0", - "has-gulplog": "0.1.0", - "lodash._reescape": "3.0.0", - "lodash._reevaluate": "3.0.0", - "lodash._reinterpolate": "3.0.0", - "lodash.template": "3.6.2", - "minimist": "1.2.0", - "multipipe": "0.1.2", - "object-assign": "3.0.0", - "replace-ext": "0.0.1", - "through2": "2.0.1", - "vinyl": "0.5.3" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } - } - }, - "gulplog": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/gulplog/-/gulplog-1.0.0.tgz", - "integrity": "sha1-4oxNRdBey77YGDY86PnFkmIp/+U=", - "dev": true, - "requires": { - "glogg": "1.0.0" - } - }, "handlebars": { "version": "4.0.11", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", @@ -1302,15 +1207,6 @@ "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=", "dev": true }, - "has-gulplog": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/has-gulplog/-/has-gulplog-0.1.0.tgz", - "integrity": "sha1-ZBTIKRNpfaUVkDl9r7EvIpZ4Ec4=", - "dev": true, - "requires": { - "sparkles": "1.0.0" - } - }, "has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", @@ -1400,15 +1296,6 @@ "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, - "indent-string": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-2.1.0.tgz", - "integrity": "sha1-ji1INIdCEhtKghi3oTfppSBJ3IA=", - "dev": true, - "requires": { - "repeating": "2.0.1" - } - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -1471,15 +1358,6 @@ "builtin-modules": "1.1.1" } }, - "is-finite": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", - "integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=", - "dev": true, - "requires": { - "number-is-nan": "1.0.1" - } - }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -1837,136 +1715,17 @@ "integrity": "sha1-Jjj8OaAzHpysGgS3F5mTHJxQ33k=", "dev": true }, - "lodash._basecopy": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz", - "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=", - "dev": true - }, - "lodash._basetostring": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz", - "integrity": "sha1-0YYdh3+CSlL2aYMtyvPuFVZqB9U=", - "dev": true - }, - "lodash._basevalues": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lodash._basevalues/-/lodash._basevalues-3.0.0.tgz", - "integrity": "sha1-W3dXYoAr3j0yl1A+JjAIIP32Ybc=", - "dev": true - }, - "lodash._getnative": { - "version": "3.9.1", - "resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz", - "integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=", - "dev": true - }, - "lodash._isiterateecall": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz", - "integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=", - "dev": true - }, - "lodash._reescape": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lodash._reescape/-/lodash._reescape-3.0.0.tgz", - "integrity": "sha1-Kx1vXf4HyKNVdT5fJ/rH8c3hYWo=", - "dev": true - }, - "lodash._reevaluate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lodash._reevaluate/-/lodash._reevaluate-3.0.0.tgz", - "integrity": "sha1-WLx0xAZklTrgsSTYBpltrKQx4u0=", - "dev": true - }, - "lodash._reinterpolate": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz", - "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=", - "dev": true - }, - "lodash._root": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz", - "integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=", - "dev": true - }, "lodash.assign": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=" }, - "lodash.escape": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-3.2.0.tgz", - "integrity": "sha1-mV7g3BjBtIzJLv+ucaEKq1tIdpg=", - "dev": true, - "requires": { - "lodash._root": "3.0.1" - } - }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, - "lodash.isarguments": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", - "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=", - "dev": true - }, - "lodash.isarray": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", - "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=", - "dev": true - }, - "lodash.keys": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz", - "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=", - "dev": true, - "requires": { - "lodash._getnative": "3.9.1", - "lodash.isarguments": "3.1.0", - "lodash.isarray": "3.0.4" - } - }, - "lodash.restparam": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz", - "integrity": "sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=", - "dev": true - }, - "lodash.template": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-3.6.2.tgz", - "integrity": "sha1-+M3sxhaaJVvpCYrosMU9N4kx0U8=", - "dev": true, - "requires": { - "lodash._basecopy": "3.0.1", - "lodash._basetostring": "3.0.1", - "lodash._basevalues": "3.0.0", - "lodash._isiterateecall": "3.0.9", - "lodash._reinterpolate": "3.0.0", - "lodash.escape": "3.2.0", - "lodash.keys": "3.1.2", - "lodash.restparam": "3.6.1", - "lodash.templatesettings": "3.1.1" - } - }, - "lodash.templatesettings": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-3.1.1.tgz", - "integrity": "sha1-+zB4RHU7Zrnxr6VOJix0UwfbqOU=", - "dev": true, - "requires": { - "lodash._reinterpolate": "3.0.0", - "lodash.escape": "3.2.0" - } - }, "log-update": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/log-update/-/log-update-1.0.2.tgz", @@ -1997,16 +1756,6 @@ "js-tokens": "3.0.1" } }, - "loud-rejection": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.6.0.tgz", - "integrity": "sha1-W0b4AUft7leIcPCG0Eghz5mOVR8=", - "dev": true, - "requires": { - "currently-unhandled": "0.4.1", - "signal-exit": "3.0.2" - } - }, "lowercase-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.0.tgz", @@ -2046,12 +1795,6 @@ "make-error": "1.3.0" } }, - "map-obj": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", - "integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=", - "dev": true - }, "mem": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", @@ -2060,38 +1803,6 @@ "mimic-fn": "1.1.0" } }, - "meow": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", - "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", - "dev": true, - "requires": { - "camelcase-keys": "2.1.0", - "decamelize": "1.2.0", - "loud-rejection": "1.6.0", - "map-obj": "1.0.1", - "minimist": "1.2.0", - "normalize-package-data": "2.3.8", - "object-assign": "4.1.1", - "read-pkg-up": "1.0.1", - "redent": "1.0.0", - "trim-newlines": "1.0.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true - } - } - }, "mime-db": { "version": "1.27.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", @@ -2245,15 +1956,6 @@ } } }, - "multipipe": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/multipipe/-/multipipe-0.1.2.tgz", - "integrity": "sha1-Ko8t33Du1WTf8tV/HhoTfZ8FB4s=", - "dev": true, - "requires": { - "duplexer2": "0.0.2" - } - }, "mysql": { "version": "2.15.0", "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.15.0.tgz", @@ -2372,12 +2074,6 @@ "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=", "dev": true }, - "object-assign": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", - "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", - "dev": true - }, "object.pick": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/object.pick/-/object.pick-1.2.0.tgz", @@ -2615,6 +2311,19 @@ "pinkie": "2.0.4" } }, + "plugin-error": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", + "integrity": "sha1-O5uzM1zPAPQl4HQ34ZJ2ln2kes4=", + "dev": true, + "requires": { + "ansi-cyan": "0.1.1", + "ansi-red": "0.1.1", + "arr-diff": "1.1.0", + "arr-union": "2.1.0", + "extend-shallow": "1.1.4" + } + }, "popsicle": { "version": "9.1.0", "resolved": "https://registry.npmjs.org/popsicle/-/popsicle-9.1.0.tgz", @@ -2775,16 +2484,6 @@ "util-deprecate": "1.0.2" } }, - "redent": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", - "integrity": "sha1-z5Fqsf1fHxbfsggi3W7H9zDCr94=", - "dev": true, - "requires": { - "indent-string": "2.1.0", - "strip-indent": "1.0.1" - } - }, "reflect-metadata": { "version": "0.1.10", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.10.tgz", @@ -2815,23 +2514,23 @@ } }, "remap-istanbul": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/remap-istanbul/-/remap-istanbul-0.9.5.tgz", - "integrity": "sha1-oYYXsfMe7Fp9vud1OCmLd1YGqqg=", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/remap-istanbul/-/remap-istanbul-0.10.0.tgz", + "integrity": "sha512-C3vinclZ2p8na07f/f+JWLchmiofgqroyxBrkKPA4kkbjsHHa94HFd5ZYkYrMEs9cbsufh53t5DFJyTK8UDVjg==", "dev": true, "requires": { "amdefine": "1.0.1", - "gulp-util": "3.0.7", "istanbul": "0.4.5", "minimatch": "3.0.4", - "source-map": "0.5.6", + "plugin-error": "0.1.2", + "source-map": "0.6.1", "through2": "2.0.1" }, "dependencies": { "source-map": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", - "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true } } @@ -2841,21 +2540,6 @@ "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" }, - "repeating": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz", - "integrity": "sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo=", - "dev": true, - "requires": { - "is-finite": "1.0.2" - } - }, - "replace-ext": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-0.0.1.tgz", - "integrity": "sha1-KbvZIHinOfC8zitO5B6DeVNSKSQ=", - "dev": true - }, "request": { "version": "2.81.0", "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", @@ -3059,12 +2743,6 @@ "amdefine": "1.0.1" } }, - "sparkles": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/sparkles/-/sparkles-1.0.0.tgz", - "integrity": "sha1-Gsu/tZJDbRC76PeFt8xvgoFQEsM=", - "dev": true - }, "spdx-correct": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-1.0.2.tgz", @@ -3181,15 +2859,6 @@ "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, - "strip-indent": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz", - "integrity": "sha1-DHlipq3vp7vUrDZkYKY4VSrhoKI=", - "dev": true, - "requires": { - "get-stdin": "4.0.1" - } - }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -3288,12 +2957,6 @@ } } }, - "time-stamp": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-1.1.0.tgz", - "integrity": "sha1-dkpaEa9QVhkhsTPztE5hhofg9cM=", - "dev": true - }, "timed-out": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", @@ -3329,12 +2992,6 @@ "punycode": "1.4.1" } }, - "trim-newlines": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", - "integrity": "sha1-WIeWa7WCpFA6QetST301ARgVphM=", - "dev": true - }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -3824,17 +3481,6 @@ } } }, - "vinyl": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-0.5.3.tgz", - "integrity": "sha1-sEVbOPxeDPMNQyUTLkYZcMIJHN4=", - "dev": true, - "requires": { - "clone": "1.0.2", - "clone-stats": "0.0.1", - "replace-ext": "0.0.1" - } - }, "wcwidth": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", From 871eb94df92a367a8d2f0169d82b5cd2c2cf5829 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 14 Jan 2018 16:54:43 +0100 Subject: [PATCH 18/21] changed postgres timestamp without time zone recognition #16 --- src/drivers/PostgresDriver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index d205d53..fbac97a 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -117,7 +117,7 @@ export class PostgresDriver extends AbstractDriver { break; case "timestamp without time zone": colInfo.ts_type = "Date" - colInfo.sql_type = "datetime" + colInfo.sql_type = "timestamp" break; case "timestamp with time zone": colInfo.ts_type = "Date" From 5cfd596ea1eca9f8a359550d3c1a79f4c2f53153 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 16 Jan 2018 22:35:53 +0100 Subject: [PATCH 19/21] adding schema information to generated ormconfig #8 #16 --- src/Engine.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Engine.ts b/src/Engine.ts index 4817c7c..92cc2a2 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -31,7 +31,7 @@ export class Engine { if (!fs.existsSync(resultPath)) fs.mkdirSync(resultPath); this.createTsConfigFile(resultPath) - this.createTypeOrm(resultPath) + this.createTypeOrmConfig(resultPath) let entitesPath = path.resolve(resultPath, './entities') Handlebars.registerHelper('toLowerCase', function (str) { return str.toLowerCase(); @@ -45,6 +45,7 @@ export class Engine { fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' }) }); } +//TODO:Move to mustache template file private createTsConfigFile(resultPath) { fs.writeFileSync(path.resolve(resultPath, 'tsconfig.json'), `{"compilerOptions": { "lib": ["es5", "es6"], @@ -56,8 +57,9 @@ export class Engine { "sourceMap": true }}`, { encoding: 'UTF-8', flag: 'w' }); } - private createTypeOrm(resultPath) { - fs.writeFileSync(path.resolve(resultPath, 'ormconfig.json'), `[ + private createTypeOrmConfig(resultPath) { + if (this.Options.schemaName == '') { + fs.writeFileSync(path.resolve(resultPath, 'ormconfig.json'), `[ { "name": "default", "driver": { @@ -73,7 +75,28 @@ export class Engine { ] } ]`, { encoding: 'UTF-8', flag: 'w' }); + } + else { + fs.writeFileSync(path.resolve(resultPath, 'ormconfig.json'), `[ + { + "name": "default", + "driver": { + "type": "${this.Options.databaseType}", + "host": "${this.Options.host}", + "port": ${this.Options.port}, + "username": "${this.Options.user}", + "password": "${this.Options.password}", + "database": "${this.Options.databaseName}", + "schema": "${this.Options.schemaName}" + }, + "entities": [ + "entities/*.js" + ] + } +]`, { encoding: 'UTF-8', flag: 'w' }); + } } + } export interface EngineOptions { host: string, From daf22e3cbeb5d8feb9039323eeb1fae0ca50d7d6 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 16 Jan 2018 22:38:28 +0100 Subject: [PATCH 20/21] dissabling oracle - no db columns<->typescript mapings, no tests --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index bfa6a03..32c4bdb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,7 +40,7 @@ var argv = Yargs .option('e', { alias: 'engine', describe: 'Database engine.', - choices: ['mssql', 'postgres', 'mysql', 'mariadb', 'oracle'], + choices: ['mssql', 'postgres', 'mysql', 'mariadb'], default: 'mssql' }) .option('o', { From cd6c61bc5a7ab2d6db5dbc571f52a84188731a81 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 16 Jan 2018 23:07:35 +0100 Subject: [PATCH 21/21] added option to skip generating config files closes #17 --- README.md | 16 +++++++++------- src/Engine.ts | 18 +++++++++++------- src/index.ts | 8 +++++++- test/utils/GeneralTestUtils.ts | 15 ++++++++++----- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bb90d0c..e8ab4e2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![npm version](https://badge.fury.io/js/typeorm-model-generator.svg)](https://badge.fury.io/js/typeorm-model-generator) [![codecov](https://codecov.io/gh/Kononnable/typeorm-model-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/Kononnable/typeorm-model-generator) -Generates models for TypeORM from existing databases. +Generates models for TypeORM from existing databases. Suported db engines: * Microsoft SQL Server * PostgreSQL @@ -19,7 +19,7 @@ Suported db engines: To install module globally simply type `npm i -g typeorm-model-generator` in your console. ### Npx way Thanks to npx you can use npm modules without polluting global installs. So nothing to do here :) ->To use `npx` you need to use npm at version at least 5.2.0. Try updating your npm by `npm i -g npm` +>To use `npx` you need to use npm at version at least 5.2.0. Try updating your npm by `npm i -g npm` ## Usage ```shell @@ -37,24 +37,26 @@ Options: -o, --output Where to place generated models. -s, --schema Schema name to create model from. Only for mssql and postgres. --ssl [boolean] [default: false] + --noConfig Doesn't create tsconfig.json and ormconfig.json + [boolean] [default: false] ``` ### Examples * Creating model from local MSSQL database - * Global module + * Global module ``` typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\ ```` - * Npx Way + * Npx Way ``` npx typeorm-model-generator -h localhost -d tempdb -u sa -x !Passw0rd -e mssql -o .\ ```` * Creating model from local Postgres database, public schema with ssl connection - * Global module + * Global module ``` typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ -s public --ssl ```` - * Npx Way + * Npx Way ``` npx typeorm-model-generator -h localhost -d postgres -u postgres -x !Passw0rd -e postgres -o .\ -s public --ssl - ```` \ No newline at end of file + ```` diff --git a/src/Engine.ts b/src/Engine.ts index 92cc2a2..7f7fb72 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -30,14 +30,17 @@ export class Engine { let resultPath = this.Options.resultsPath if (!fs.existsSync(resultPath)) fs.mkdirSync(resultPath); - this.createTsConfigFile(resultPath) - this.createTypeOrmConfig(resultPath) - let entitesPath = path.resolve(resultPath, './entities') + let entitesPath = resultPath + if (!this.Options.noConfigs) { + this.createTsConfigFile(resultPath) + this.createTypeOrmConfig(resultPath) + entitesPath = path.resolve(resultPath, './entities') + if (!fs.existsSync(entitesPath)) + fs.mkdirSync(entitesPath); + } Handlebars.registerHelper('toLowerCase', function (str) { return str.toLowerCase(); }); - if (!fs.existsSync(entitesPath)) - fs.mkdirSync(entitesPath); let compliedTemplate = Handlebars.compile(template, { noEscape: true }) databaseModel.entities.forEach(element => { let resultFilePath = path.resolve(entitesPath, element.EntityName + '.ts'); @@ -45,7 +48,7 @@ export class Engine { fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' }) }); } -//TODO:Move to mustache template file + //TODO:Move to mustache template file private createTsConfigFile(resultPath) { fs.writeFileSync(path.resolve(resultPath, 'tsconfig.json'), `{"compilerOptions": { "lib": ["es5", "es6"], @@ -107,5 +110,6 @@ export interface EngineOptions { resultsPath: string, databaseType: string, schemaName: string, - ssl: boolean + ssl: boolean, + noConfigs: boolean } diff --git a/src/index.ts b/src/index.ts index 32c4bdb..ebe42e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,6 +56,11 @@ var argv = Yargs boolean: true, default: false }) + .option('noConfig', { + boolean: true, + describe: `Doesn't create tsconfig.json and ormconfig.json`, + default: false + }) .argv; @@ -100,7 +105,8 @@ let engine = new Engine( databaseType: argv.e, resultsPath: argv.o, schemaName: argv.s || standardSchema, - ssl: argv.ssl + ssl: argv.ssl, + noConfigs: argv.noConfig }); console.log(`[${new Date().toLocaleTimeString()}] Starting creation of model classes.`); diff --git a/test/utils/GeneralTestUtils.ts b/test/utils/GeneralTestUtils.ts index 68a88ad..fb00ae1 100644 --- a/test/utils/GeneralTestUtils.ts +++ b/test/utils/GeneralTestUtils.ts @@ -49,7 +49,8 @@ export async function createMSSQLModels(filesOrgPath: string, resultsPath: strin databaseType: 'mssql', resultsPath: resultsPath, schemaName: 'dbo', - ssl: yn(process.env.MSSQL_SSL) + ssl: yn(process.env.MSSQL_SSL), + noConfigs: false }); @@ -92,7 +93,8 @@ export async function createPostgresModels(filesOrgPath: string, resultsPath: st databaseType: 'postgres', resultsPath: resultsPath, schemaName: 'public', - ssl: yn(process.env.POSTGRES_SSL) + ssl: yn(process.env.POSTGRES_SSL), + noConfigs: false }); @@ -136,7 +138,8 @@ export async function createMysqlModels(filesOrgPath: string, resultsPath: strin databaseType: 'mysql', resultsPath: resultsPath, schemaName: 'ignored', - ssl: yn(process.env.MYSQL_SSL) + ssl: yn(process.env.MYSQL_SSL), + noConfigs: false }); @@ -180,7 +183,8 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str databaseType: 'mariadb', resultsPath: resultsPath, schemaName: 'ignored', - ssl: yn(process.env.MARIADB_SSL) + ssl: yn(process.env.MARIADB_SSL), + noConfigs: false }); @@ -226,7 +230,8 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st databaseType: 'oracle', resultsPath: resultsPath, schemaName: String(process.env.ORACLE_Username), - ssl: yn(process.env.ORACLE_SSL) + ssl: yn(process.env.ORACLE_SSL), + noConfigs: false });