Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pgsql/index.js query() Catch Block #555

Merged
merged 3 commits into from May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}
}