Skip to content

Commit 6d47026

Browse files
authored
Merge pull request brianc#57 from brianc/bmc/lint-changes
Fix for pg@7.x
2 parents 1cdad4d + be03212 commit 6d47026

13 files changed

+1501
-1991
lines changed

.eslintrc

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
2-
"extends": "standard",
2+
"extends": ["eslint:recommended"],
3+
"plugins": ["prettier"],
4+
"rules": {
5+
"prettier/prettier": "error",
6+
"prefer-const": "error",
7+
"no-var": "error"
8+
},
39
"env": {
10+
"es6": true,
11+
"node": true,
412
"mocha": true
5-
},
6-
"rules": {
7-
"no-new-func": "off"
813
}
914
}

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ language: node_js
22
dist: trusty
33
sudo: false
44
node_js:
5-
- "4.2"
6-
- "6"
75
- "8"
6+
- "10"
7+
- "12"
88
env:
99
- PGUSER=postgres
1010
services:

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
.PHONY: publish-patch test
2-
1+
.PHONY: test
32
test:
43
npm test
54

5+
.PHONY: patch
66
patch: test
77
npm version patch -m "Bump version"
88
git push origin master --tags
99
npm publish
1010

11+
.PHONY: minor
1112
minor: test
1213
npm version minor -m "Bump version"
1314
git push origin master --tags

index.js

+43-34
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const prepare = require('pg/lib/utils.js').prepareValue
44
const EventEmitter = require('events').EventEmitter
55
const util = require('util')
66

7-
var nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl
7+
let nextUniqueID = 1 // concept borrowed from org.postgresql.core.v3.QueryExecutorImpl
88

9-
function Cursor (text, values, config) {
9+
function Cursor(text, values, config) {
1010
EventEmitter.call(this)
1111

1212
this._conf = config || {}
@@ -15,33 +15,42 @@ function Cursor (text, values, config) {
1515
this.connection = null
1616
this._queue = []
1717
this.state = 'initialized'
18-
this._result = new Result(this._conf.rowMode)
18+
this._result = new Result(this._conf.rowMode, this._conf.types)
1919
this._cb = null
2020
this._rows = null
2121
this._portal = null
2222
}
2323

2424
util.inherits(Cursor, EventEmitter)
2525

26-
Cursor.prototype.submit = function (connection) {
26+
Cursor.prototype.submit = function(connection) {
2727
this.connection = connection
28-
this._portal = 'C_' + (nextUniqueID++)
28+
this._portal = 'C_' + nextUniqueID++
2929

3030
const con = connection
3131

32-
con.parse({
33-
text: this.text
34-
}, true)
35-
36-
con.bind({
37-
portal: this._portal,
38-
values: this.values
39-
}, true)
40-
41-
con.describe({
42-
type: 'P',
43-
name: this._portal // AWS Redshift requires a portal name
44-
}, true)
32+
con.parse(
33+
{
34+
text: this.text,
35+
},
36+
true
37+
)
38+
39+
con.bind(
40+
{
41+
portal: this._portal,
42+
values: this.values,
43+
},
44+
true
45+
)
46+
47+
con.describe(
48+
{
49+
type: 'P',
50+
name: this._portal, // AWS Redshift requires a portal name
51+
},
52+
true
53+
)
4554

4655
con.flush()
4756

@@ -60,25 +69,25 @@ Cursor.prototype.submit = function (connection) {
6069
})
6170
}
6271

63-
Cursor.prototype._shiftQueue = function () {
72+
Cursor.prototype._shiftQueue = function() {
6473
if (this._queue.length) {
6574
this._getRows.apply(this, this._queue.shift())
6675
}
6776
}
6877

69-
Cursor.prototype.handleRowDescription = function (msg) {
78+
Cursor.prototype.handleRowDescription = function(msg) {
7079
this._result.addFields(msg.fields)
7180
this.state = 'idle'
7281
this._shiftQueue()
7382
}
7483

75-
Cursor.prototype.handleDataRow = function (msg) {
84+
Cursor.prototype.handleDataRow = function(msg) {
7685
const row = this._result.parseRow(msg.fields)
7786
this.emit('row', row, this._result)
7887
this._rows.push(row)
7988
}
8089

81-
Cursor.prototype._sendRows = function () {
90+
Cursor.prototype._sendRows = function() {
8291
this.state = 'idle'
8392
setImmediate(() => {
8493
const cb = this._cb
@@ -94,34 +103,34 @@ Cursor.prototype._sendRows = function () {
94103
})
95104
}
96105

97-
Cursor.prototype.handleCommandComplete = function (msg) {
106+
Cursor.prototype.handleCommandComplete = function(msg) {
98107
this._result.addCommandComplete(msg)
99108
this.connection.sync()
100109
}
101110

102-
Cursor.prototype.handlePortalSuspended = function () {
111+
Cursor.prototype.handlePortalSuspended = function() {
103112
this._sendRows()
104113
}
105114

106-
Cursor.prototype.handleReadyForQuery = function () {
115+
Cursor.prototype.handleReadyForQuery = function() {
107116
this._sendRows()
108117
this.emit('end', this._result)
109118
this.state = 'done'
110119
}
111120

112-
Cursor.prototype.handleEmptyQuery = function () {
121+
Cursor.prototype.handleEmptyQuery = function() {
113122
this.connection.sync()
114123
}
115124

116-
Cursor.prototype.handleError = function (msg) {
125+
Cursor.prototype.handleError = function(msg) {
117126
this.state = 'error'
118127
this._error = msg
119128
// satisfy any waiting callback
120129
if (this._cb) {
121130
this._cb(msg)
122131
}
123132
// dispatch error to all waiting callbacks
124-
for (var i = 0; i < this._queue.length; i++) {
133+
for (let i = 0; i < this._queue.length; i++) {
125134
this._queue.pop()[1](msg)
126135
}
127136

@@ -133,41 +142,41 @@ Cursor.prototype.handleError = function (msg) {
133142
this.connection.sync()
134143
}
135144

136-
Cursor.prototype._getRows = function (rows, cb) {
145+
Cursor.prototype._getRows = function(rows, cb) {
137146
this.state = 'busy'
138147
this._cb = cb
139148
this._rows = []
140149
const msg = {
141150
portal: this._portal,
142-
rows: rows
151+
rows: rows,
143152
}
144153
this.connection.execute(msg, true)
145154
this.connection.flush()
146155
}
147156

148-
Cursor.prototype.end = function (cb) {
157+
Cursor.prototype.end = function(cb) {
149158
if (this.state !== 'initialized') {
150159
this.connection.sync()
151160
}
152161
this.connection.once('end', cb)
153162
this.connection.end()
154163
}
155164

156-
Cursor.prototype.close = function (cb) {
165+
Cursor.prototype.close = function(cb) {
157166
if (this.state === 'done') {
158167
return setImmediate(cb)
159168
}
160169
this.connection.close({ type: 'P' })
161170
this.connection.sync()
162171
this.state = 'done'
163172
if (cb) {
164-
this.connection.once('closeComplete', function () {
173+
this.connection.once('closeComplete', function() {
165174
cb()
166175
})
167176
}
168177
}
169178

170-
Cursor.prototype.read = function (rows, cb) {
179+
Cursor.prototype.read = function(rows, cb) {
171180
if (this.state === 'idle') {
172181
return this._getRows(rows, cb)
173182
}

0 commit comments

Comments
 (0)