Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #44 from jafl/redshift-requires-portal-name
Browse files Browse the repository at this point in the history
fix: AWS Redshift requires a portal name to honor fetchSize
  • Loading branch information
brianc authored Jan 8, 2019
2 parents 73506d3 + 37997fe commit 0a10525
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const prepare = require('pg/lib/utils.js').prepareValue
const EventEmitter = require('events').EventEmitter
const util = require('util')

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

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

Expand All @@ -16,12 +18,14 @@ function Cursor (text, values, config) {
this._result = new Result(this._conf.rowMode)
this._cb = null
this._rows = null
this._portal = null
}

util.inherits(Cursor, EventEmitter)

Cursor.prototype.submit = function (connection) {
this.connection = connection
this._portal = 'C_' + (nextUniqueID++)

const con = connection

Expand All @@ -30,12 +34,13 @@ Cursor.prototype.submit = function (connection) {
}, true)

con.bind({
portal: this._portal,
values: this.values
}, true)

con.describe({
type: 'P',
name: '' // use unamed portal
name: this._portal // AWS Redshift requires a portal name
}, true)

con.flush()
Expand Down Expand Up @@ -132,7 +137,7 @@ Cursor.prototype._getRows = function (rows, cb) {
this._cb = cb
this._rows = []
const msg = {
portal: '',
portal: this._portal,
rows: rows
}
this.connection.execute(msg, true)
Expand Down

0 comments on commit 0a10525

Please sign in to comment.