From 9f866fa99ffe86473b8a9b6cd6af1ed73668e038 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Tue, 28 Mar 2017 00:29:37 +0200 Subject: [PATCH] fixed connection to database; enumerating all the tables --- src/Engine.ts | 4 ++-- src/drivers/MssqlDriver.ts | 49 +++++++++++++++++++++++++------------- src/index.ts | 2 +- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/Engine.ts b/src/Engine.ts index d2225ef..e72c01c 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -16,8 +16,8 @@ export class Engine { } return true; } - private getEntitiesInfo(database: string, server: string, port: number, user: string, password: string): EntityInfo[] { - this.driver.GetDataFromServer(database, server, port, user, password) + private async getEntitiesInfo(database: string, server: string, port: number, user: string, password: string): Promise { + await this.driver.GetDataFromServer(database, server, port, user, password) return []; } private createModelFromMetadata(entities: EntityInfo[]) { diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index d527f4e..6cb5321 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -5,10 +5,16 @@ import * as MSSQL from 'mssql' */ export class MssqlDriver extends AbstractDriver { async GetAllTables(): Promise { - let request = new MSSQL.Request(this.Connection) - let response = await request.query("SELECT TABLE_SCHEMA,TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"); -let x=1; - throw new Error('Method not implemented.'); + 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'"); + let ret:EntityInfo[]=[]; + response.forEach( (val)=>{ + let ent:EntityInfo={}; + ent.EntityName=val.TABLE_NAME; + ret.push(ent); + }) + return ret; } GetCoulmnsFromEntity(entity: EntityInfo[]) { throw new Error('Method not implemented.'); @@ -32,19 +38,28 @@ let x=1; port: port, user: user, password: password, - // driver: 'msnodesqlv8' - } - this.Connection = new MSSQL.Connection(config) - try { - var con:any = this.Connection; - let x = await con.connect("mssql://sa:password@localhost/AdventureWorksDW2014") - // await this.Connection.connect( (err)=>{console.log(err);console.log('a');}) - } catch (error) { - //TODO: errors on Connection - console.error(error); - process.abort(); + options: { + encrypt: true, // Use this if you're on Windows Azure + appName: 'typeorm-model-generator' + } } + + + let promise = new Promise( + (resolve, reject) => { + this.Connection = new MSSQL.Connection(config, (err) => { + if (!err) { + //Connection successfull + resolve(true) + } + else { + //TODO:Report errors + reject(err) + } + }); + } + ) + + await promise; } - - } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3f33186..44d49a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,5 +66,5 @@ let engine = new Engine( }); engine.createModelFromDatabase().then( ()=>{ - process.abort(); + // process.abort(); })