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

Method query

packages/pg/lib/client.js:626–720  ·  view source on GitHub ↗
(config, values, callback)

Source from the content-addressed store, hash-verified

624 }
625
626 query(config, values, callback) {
627 // can take in strings, config object or query object
628 let query
629 let result
630
631 if (config == null) {
632 throw new TypeError('Client was passed a null or undefined query')
633 }
634
635 if (typeof config.submit === 'function') {
636 result = query = config
637 if (!query.callback) {
638 if (typeof values === 'function') {
639 query.callback = values
640 } else if (callback) {
641 query.callback = callback
642 }
643 }
644 } else {
645 query = new Query(config, values, callback)
646 if (!query.callback) {
647 result = new this._Promise((resolve, reject) => {
648 query.callback = (err, res) => (err ? reject(err) : resolve(res))
649 }).catch((err) => {
650 // replace the stack trace that leads to `TCP.onStreamRead` with one that leads back to the
651 // application that created the query
652 Error.captureStackTrace(err)
653 throw err
654 })
655 } else if (typeof query.callback !== 'function') {
656 throw new TypeError('callback is not a function')
657 }
658 }
659
660 const readTimeout = config.query_timeout || this.connectionParameters.query_timeout
661 if (readTimeout) {
662 const queryCallback = query.callback || (() => {})
663
664 const readTimeoutTimer = setTimeout(() => {
665 const error = new Error('Query read timeout')
666
667 process.nextTick(() => {
668 query.handleError(error, this.connection)
669 })
670
671 queryCallback(error)
672
673 // we already returned an error,
674 // just do nothing if query completes
675 query.callback = () => {}
676
677 // Remove from queue
678 const index = this._queryQueue.indexOf(query)
679 if (index > -1) {
680 this._queryQueue.splice(index, 1)
681 }
682
683 this._pulseQueryQueue()

Callers 15

connectClientFunction · 0.95
runFunction · 0.95
innerFunctionFunction · 0.95
getAppNameFunction · 0.95
getServerVersionNumFunction · 0.95
killIdleQueryFunction · 0.95
getStatementTimeoutFunction · 0.95
testErrorBufferFunction · 0.95
setupClientFunction · 0.95
dump-db-types.jsFile · 0.45
submitMethod · 0.45

Calls 2

_pulseQueryQueueMethod · 0.95
handleErrorMethod · 0.45

Tested by

no test coverage detected