MCPcopy Index your code
hub / github.com/brianc/node-postgres / submit

Method submit

packages/pg/lib/query.js:152–183  ·  view source on GitHub ↗
(connection)

Source from the content-addressed store, hash-verified

150 }
151
152 submit(connection) {
153 if (typeof this.text !== 'string' && typeof this.name !== 'string') {
154 return new Error('A query must have either text or a name. Supplying neither is unsupported.')
155 }
156 const previous = connection.parsedStatements[this.name]
157 if (this.text && previous && this.text !== previous) {
158 return new Error(`Prepared statements must be unique - '${this.name}' was used for a different statement`)
159 }
160 if (this.values && !Array.isArray(this.values)) {
161 return new Error('Query values must be an array')
162 }
163 if (this.requiresPreparation()) {
164 // If we're using the extended query protocol we fire off several separate commands
165 // to the backend. On some versions of node & some operating system versions
166 // the network stack writes each message separately instead of buffering them together
167 // causing the client & network to send more slowly. Corking & uncorking the stream
168 // allows node to buffer up the messages internally before sending them all off at once.
169 // note: we're checking for existence of cork/uncork because some versions of streams
170 // might not have this (cloudflare?)
171 connection.stream.cork && connection.stream.cork()
172 try {
173 this.prepare(connection)
174 } finally {
175 // while unlikely for this.prepare to throw, if it does & we don't uncork this stream
176 // this client becomes unresponsive, so put in finally block "just in case"
177 connection.stream.uncork && connection.stream.uncork()
178 }
179 } else {
180 connection.query(this.text)
181 }
182 return null
183 }
184
185 hasBeenParsed(connection) {
186 return this.name && connection.parsedStatements[this.name]

Callers 2

_pulseQueryQueueMethod · 0.45
client.jsFile · 0.45

Calls 3

requiresPreparationMethod · 0.95
prepareMethod · 0.95
queryMethod · 0.45

Tested by

no test coverage detected