Implement handleEmptyQuery for pg-query-stream. (#2106)

This commit is contained in:
Kyle Lilly 2020-02-19 13:12:47 -05:00 committed by GitHub
parent 823153138f
commit c2f4b284b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -15,6 +15,7 @@ class PgQueryStream extends Readable {
this.handleCommandComplete = this.cursor.handleCommandComplete.bind(this.cursor)
this.handleReadyForQuery = this.cursor.handleReadyForQuery.bind(this.cursor)
this.handleError = this.cursor.handleError.bind(this.cursor)
this.handleEmptyQuery = this.cursor.handleEmptyQuery.bind(this.cursor)
}
submit(connection) {

View File

@ -0,0 +1,20 @@
const assert = require('assert')
const helper = require('./helper')
const QueryStream = require('../')
helper('empty-query', function (client) {
it('handles empty query', function(done) {
const stream = new QueryStream('-- this is a comment', [])
const query = client.query(stream)
query.on('end', function () {
// nothing should happen for empty query
done();
}).on('data', function () {
// noop to kick off reading
})
})
it('continues to function after stream', function (done) {
client.query('SELECT NOW()', done)
})
})