Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pg-query-stream): invoke this.callback on cursor end/error #2810

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/pg-query-stream/src/index.ts
Expand Up @@ -13,6 +13,7 @@ class QueryStream extends Readable implements Submittable {
cursor: any
_result: any

callback: Function
handleRowDescription: Function
handleDataRow: Function
handlePortalSuspended: Function
Expand All @@ -26,6 +27,11 @@ class QueryStream extends Readable implements Submittable {

super({ objectMode: true, autoDestroy: true, highWaterMark: batchSize || highWaterMark })
this.cursor = new Cursor(text, values, config)
this.cursor.on('end', (result) => {
this.callback && this.callback(null, result)
}).on('error', (err) => {
this.callback && this.callback(err)
})

// delegate Submittable callbacks to cursor
this.handleRowDescription = this.cursor.handleRowDescription.bind(this.cursor)
Expand Down
8 changes: 6 additions & 2 deletions packages/pg/lib/client.js
Expand Up @@ -511,8 +511,12 @@ class Client extends EventEmitter {
} else if (typeof config.submit === 'function') {
readTimeout = config.query_timeout || this.connectionParameters.query_timeout
result = query = config
if (typeof values === 'function') {
query.callback = query.callback || values
if (!query.callback) {
if (typeof values === 'function') {
query.callback = values
} else if (callback) {
query.callback = callback
}
}
} else {
readTimeout = this.connectionParameters.query_timeout
Expand Down