MCPcopy
hub / github.com/brianc/node-postgres / query

Method query

packages/pg-pool/index.js:431–486  ·  view source on GitHub ↗
(text, values, cb)

Source from the content-addressed store, hash-verified

429 }
430
431 query(text, values, cb) {
432 // guard clause against passing a function as the first parameter
433 if (typeof text === 'function') {
434 const response = promisify(this.Promise, text)
435 setImmediate(function () {
436 return response.callback(new Error('Passing a function as the first parameter to pool.query is not supported'))
437 })
438 return response.result
439 }
440
441 // allow plain text query without values, but callback
442 if (typeof values === 'function') {
443 cb = values
444 values = undefined
445 }
446 const response = promisify(this.Promise, cb)
447 cb = response.callback
448
449 this.connect((err, client) => {
450 if (err) {
451 return cb(err)
452 }
453
454 let clientReleased = false
455 const onError = (err) => {
456 if (clientReleased) {
457 return
458 }
459 clientReleased = true
460 client.release(err)
461 cb(err)
462 }
463
464 client.once('error', onError)
465 this.log('dispatching query')
466 try {
467 client.query(text, values, (err, res) => {
468 this.log('query dispatched')
469 client.removeListener('error', onError)
470 if (clientReleased) {
471 return
472 }
473 clientReleased = true
474 client.release(err)
475 if (err) {
476 return cb(err)
477 }
478 return cb(undefined, res)
479 })
480 } catch (err) {
481 client.release(err)
482 return cb(err)
483 }
484 })
485 return response.result
486 }
487
488 end(cb) {

Callers 15

innerFunctionFunction · 0.95
testErrorBufferFunction · 0.95
lifecycle-hooks.jsFile · 0.45
index.jsFile · 0.45
submittable.jsFile · 0.45
logging.jsFile · 0.45
runErrorQueryFunction · 0.45
error-handling.jsFile · 0.45
sizing.jsFile · 0.45

Calls 3

connectMethod · 0.95
promisifyFunction · 0.85
cbFunction · 0.85

Tested by

no test coverage detected