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

Function onReadable

packages/pg-native/lib/copy-stream.js:124–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122 }
123
124 const onReadable = function () {
125 // read waiting data from the socket
126 // e.g. clear the pending 'select'
127 if (!pq.consumeInput()) {
128 return readError()
129 }
130
131 // check if there is still outstanding data
132 // if so, wait for it all to come in
133 if (pq.isBusy()) {
134 return
135 }
136
137 // load our result object
138 pq.getResult()
139
140 // "read until results return null"
141 // or in our case ensure we only have one result
142 if (pq.getResult() && pq.resultStatus() !== 'PGRES_COPY_OUT') {
143 return readError('Only one result at a time is accepted')
144 }
145
146 if (pq.resultStatus() === 'PGRES_FATAL_ERROR') {
147 return readError()
148 }
149
150 cleanup()
151 return cb(null)
152 }
153 pq.on('readable', onReadable)
154 pq.startReader()
155}

Callers

nothing calls this directly

Calls 3

readErrorFunction · 0.85
cleanupFunction · 0.85
cbFunction · 0.85

Tested by

no test coverage detected