Skip to content

Commit

Permalink
Merge pull request #555 from EdwardChapman/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mtxr committed May 6, 2020
2 parents 640dc89 + a7711b9 commit aa9a24a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/drivers/src/driver/pgsql/index.ts
@@ -1,4 +1,4 @@
import { Pool, PoolConfig, types, FieldDef } from 'pg';
import { Pool, PoolConfig, PoolClient, types, FieldDef } from 'pg';
import Queries from './queries';
import { IConnectionDriver, NSDatabase } from '@sqltools/types';
import AbstractDriver from '../../lib/abstract';
Expand Down Expand Up @@ -68,9 +68,10 @@ export default class PostgreSQL extends AbstractDriver<Pool, PoolConfig> impleme

public query(query: string): Promise<NSDatabase.IResult[]> {
const messages = [];
let cli : PoolClient;
return this.open()
.then(async (pool) => {
const cli = await pool.connect();
cli = await pool.connect();
cli.on('notice', notice => messages.push(`${notice.name.toUpperCase()}: ${notice.message}`));
const results = await cli.query({text: query, rowMode: 'array'});
cli.release();
Expand All @@ -94,7 +95,9 @@ export default class PostgreSQL extends AbstractDriver<Pool, PoolConfig> impleme
};
});
})
.catch(err => ([{
.catch(err => {
cli && cli.release();
return ([{
connId: this.getId(),
cols: [],
messages: messages.concat([
Expand All @@ -106,7 +109,8 @@ export default class PostgreSQL extends AbstractDriver<Pool, PoolConfig> impleme
error: true,
query,
results: [],
}]))
}])
})
}

private getColumnNames(fields: FieldDef[]): string[] {
Expand Down Expand Up @@ -186,4 +190,4 @@ export default class PostgreSQL extends AbstractDriver<Pool, PoolConfig> impleme
await cli.query('SELECT 1');
cli.release();
}
}
}

0 comments on commit aa9a24a

Please sign in to comment.