Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/pg-cursor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const util = require('util')

let nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl

function Cursor (text, values, config) {
function Cursor(text, values, config) {
EventEmitter.call(this)

this._conf = config || {}
Expand Down Expand Up @@ -192,7 +192,7 @@ Cursor.prototype.close = function (cb) {
this._closePortal()
this.state = 'done'
if (cb) {
this.connection.once('closeComplete', function () {
this.connection.once('readyForQuery', function () {
cb()
})
}
Expand Down
8 changes: 6 additions & 2 deletions packages/pg-cursor/test/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe('close', function () {
beforeEach(function (done) {
const client = (this.client = new pg.Client())
client.connect(done)
client.on('drain', client.end.bind(client))
})

this.afterEach(function (done) {
this.client.end(done)
})

it('can close a finished cursor without a callback', function (done) {
Expand All @@ -34,8 +37,9 @@ describe('close', function () {
const cursor = new Cursor(text)
const client = this.client
client.query(cursor)
cursor.read(25, function (err) {
cursor.read(25, function (err, rows) {
assert.ifError(err)
assert.strictEqual(rows.length, 25)
cursor.close(function (err) {
assert.ifError(err)
client.query('SELECT NOW()', done)
Expand Down