fixed connection to database;

enumerating all the tables
This commit is contained in:
Kononnable 2017-03-28 00:29:37 +02:00
parent 35b230731a
commit 9f866fa99f
3 changed files with 35 additions and 20 deletions

View File

@ -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<EntityInfo[]> {
await this.driver.GetDataFromServer(database, server, port, user, password)
return [];
}
private createModelFromMetadata(entities: EntityInfo[]) {

View File

@ -5,10 +5,16 @@ import * as MSSQL from 'mssql'
*/
export class MssqlDriver extends AbstractDriver {
async GetAllTables(): Promise<EntityInfo[]> {
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[]=<EntityInfo[]>[];
response.forEach( (val)=>{
let ent:EntityInfo=<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<boolean>(
(resolve, reject) => {
this.Connection = new MSSQL.Connection(config, (err) => {
if (!err) {
//Connection successfull
resolve(true)
}
else {
//TODO:Report errors
reject(err)
}
});
}
)
await promise;
}
}

View File

@ -66,5 +66,5 @@ let engine = new Engine(
});
engine.createModelFromDatabase().then( ()=>{
process.abort();
// process.abort();
})