From c2f4b284b1748562244fa56bcaa250413c00c454 Mon Sep 17 00:00:00 2001 From: Kyle Lilly Date: Wed, 19 Feb 2020 13:12:47 -0500 Subject: [PATCH] Implement handleEmptyQuery for pg-query-stream. (#2106) --- packages/pg-query-stream/index.js | 1 + packages/pg-query-stream/test/empty-query.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/pg-query-stream/test/empty-query.js diff --git a/packages/pg-query-stream/index.js b/packages/pg-query-stream/index.js index 20073381..20c56b38 100644 --- a/packages/pg-query-stream/index.js +++ b/packages/pg-query-stream/index.js @@ -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) { diff --git a/packages/pg-query-stream/test/empty-query.js b/packages/pg-query-stream/test/empty-query.js new file mode 100644 index 00000000..75603174 --- /dev/null +++ b/packages/pg-query-stream/test/empty-query.js @@ -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) + }) +}) \ No newline at end of file