better handling fatal errors, codecov treshold set

This commit is contained in:
Kononnable 2017-12-31 01:20:53 +01:00
parent f82fa172c9
commit a07f347e4b
9 changed files with 117 additions and 103 deletions

View File

@ -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%

View File

@ -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
}
}

12
src/Utils.ts Normal file
View File

@ -0,0 +1,12 @@
import * as data from './../../package.json'
export function LogFatalError(errText:string, isABug:boolean=true,errObject?:any) {
let x = <any>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()
}

View File

@ -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[] = <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;
}
}
}

View File

@ -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[] = <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;
}
}
}

View File

@ -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<EntityInfo[]> {
let response :any[][] = ( await this.Connection.execute(` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`)).rows!;
let ret: EntityInfo[] = <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[] = <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<boolean> {
return true;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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.`);

4
src/typings.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
declare module "*.json" {
const value: any;
export default value;
}