From 98e253bd1bd5d437db9dfb2eda9fba394cd43331 Mon Sep 17 00:00:00 2001 From: Rafael <rpd17@inf.ufpr.br> Date: Mon, 23 Apr 2018 10:02:01 -0300 Subject: [PATCH] finished postgres Signed-off-by: Rafael <rpd17@inf.ufpr.br> --- src/adapter/postgres.ts | 17 ++++------------- src/api/controllers/collect.spec.ts | 1 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/adapter/postgres.ts b/src/adapter/postgres.ts index 6c70e28f..e01b2bb3 100644 --- a/src/adapter/postgres.ts +++ b/src/adapter/postgres.ts @@ -33,7 +33,10 @@ export class PostgresAdapter extends SQLAdapter { } public getDataFromView(view: View, cb: (error: Error, result?: any[]) => void): void { const query = this.getQueryFromView(view); + this.executeQuery(query, cb); + } + private executeQuery(query: string, cb: (err: Error, result?: any[]) => void): void{ this.pool.connect((err, client, done) => { if (err) { cb (err); @@ -48,19 +51,7 @@ export class PostgresAdapter extends SQLAdapter { } public insertIntoSource(source: Source, data: any[], cb: (err: Error, result?: any[]) => void): void { const query = this.getQueryFromSource(source, data); - - this.pool.connect((err, client, done) => { - if (err) { - cb (err); - return; - } - client.query(query, [], (error, result) => { - // call 'done()' to release client back to pool - done(); - cb(error, (result) ? result.rows : null); - }); - }); - + this.executeQuery(query, cb); } public materializeView(view: View): boolean { diff --git a/src/api/controllers/collect.spec.ts b/src/api/controllers/collect.spec.ts index 45bc6d98..10d0fb5a 100644 --- a/src/api/controllers/collect.spec.ts +++ b/src/api/controllers/collect.spec.ts @@ -44,7 +44,6 @@ describe("API collect controller", () => { let adapter: Adapter; let fixture; before(function (done): void { - // Arrow function not used to get acces to this and skip the test config = ConfigParser.parse("config/test.yaml"); if (config.adapter === "postgres") { fixture = new FixPostgres(config.connection); -- GitLab