diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index a2b7c2686..d2e7038bd 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -515,7 +515,7 @@ class Client extends EventEmitter { query.callback = query.callback || values } } else { - readTimeout = this.connectionParameters.query_timeout + readTimeout = config.query_timeout || this.connectionParameters.query_timeout query = new Query(config, values, callback) if (!query.callback) { result = new this._Promise((resolve, reject) => { diff --git a/packages/pg/lib/native/client.js b/packages/pg/lib/native/client.js index 6fb2e0608..ff02178d1 100644 --- a/packages/pg/lib/native/client.js +++ b/packages/pg/lib/native/client.js @@ -167,7 +167,7 @@ Client.prototype.query = function (config, values, callback) { config.callback = values } } else { - readTimeout = this.connectionParameters.query_timeout + readTimeout = config.query_timeout || this.connectionParameters.query_timeout query = new NativeQuery(config, values, callback) if (!query.callback) { let resolveOut, rejectOut diff --git a/packages/pg/test/integration/client/api-tests.js b/packages/pg/test/integration/client/api-tests.js index abaab69fb..4fcdc0284 100644 --- a/packages/pg/test/integration/client/api-tests.js +++ b/packages/pg/test/integration/client/api-tests.js @@ -102,6 +102,21 @@ suite.test('query no timeout', (cb) => { }) }) +suite.test('query with timeout on query basis', (cb) => { + const pool = new pg.Pool() + pool.connect().then((client) => { + client.query( + {text: 'SELECT pg_sleep(20)', query_timeout: 1000}, + assert.calls(function (err, result) { + assert(err) + assert(err.message === 'Query read timeout') + client.release() + pool.end(cb) + }) + ) + }) +}) + suite.test('callback API', (done) => { const client = new helper.Client() client.query('CREATE TEMP TABLE peep(name text)')