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

Commit

Permalink
Apply prettier to code, change lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed Oct 25, 2019
1 parent 1cdad4d commit 414fac6
Show file tree
Hide file tree
Showing 13 changed files with 1,699 additions and 1,937 deletions.
12 changes: 8 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"extends": "standard",
"env": {
"mocha": true
},
"extends": "eslint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"no-new-func": "off"
},
"env": {
"es6": true,
"node": true,
"mocha": true
}
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: node_js
dist: trusty
sudo: false
node_js:
- "4.2"
- "6"
- "8"
- "10"
- "12"
env:
- PGUSER=postgres
services:
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
.PHONY: publish-patch test

.PHONY: test
test:
npm test

.PHONY: patch
patch: test
npm version patch -m "Bump version"
git push origin master --tags
npm publish

.PHONY: minor
minor: test
npm version minor -m "Bump version"
git push origin master --tags
Expand Down
71 changes: 40 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const util = require('util')

var 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 All @@ -23,25 +23,34 @@ function Cursor (text, values, config) {

util.inherits(Cursor, EventEmitter)

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

const con = connection

con.parse({
text: this.text
}, true)

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

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

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

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

con.flush()

Expand All @@ -60,25 +69,25 @@ Cursor.prototype.submit = function (connection) {
})
}

Cursor.prototype._shiftQueue = function () {
Cursor.prototype._shiftQueue = function() {
if (this._queue.length) {
this._getRows.apply(this, this._queue.shift())
}
}

Cursor.prototype.handleRowDescription = function (msg) {
Cursor.prototype.handleRowDescription = function(msg) {
this._result.addFields(msg.fields)
this.state = 'idle'
this._shiftQueue()
}

Cursor.prototype.handleDataRow = function (msg) {
Cursor.prototype.handleDataRow = function(msg) {
const row = this._result.parseRow(msg.fields)
this.emit('row', row, this._result)
this._rows.push(row)
}

Cursor.prototype._sendRows = function () {
Cursor.prototype._sendRows = function() {
this.state = 'idle'
setImmediate(() => {
const cb = this._cb
Expand All @@ -94,26 +103,26 @@ Cursor.prototype._sendRows = function () {
})
}

Cursor.prototype.handleCommandComplete = function (msg) {
Cursor.prototype.handleCommandComplete = function(msg) {
this._result.addCommandComplete(msg)
this.connection.sync()
}

Cursor.prototype.handlePortalSuspended = function () {
Cursor.prototype.handlePortalSuspended = function() {
this._sendRows()
}

Cursor.prototype.handleReadyForQuery = function () {
Cursor.prototype.handleReadyForQuery = function() {
this._sendRows()
this.emit('end', this._result)
this.state = 'done'
}

Cursor.prototype.handleEmptyQuery = function () {
Cursor.prototype.handleEmptyQuery = function() {
this.connection.sync()
}

Cursor.prototype.handleError = function (msg) {
Cursor.prototype.handleError = function(msg) {
this.state = 'error'
this._error = msg
// satisfy any waiting callback
Expand All @@ -133,41 +142,41 @@ Cursor.prototype.handleError = function (msg) {
this.connection.sync()
}

Cursor.prototype._getRows = function (rows, cb) {
Cursor.prototype._getRows = function(rows, cb) {
this.state = 'busy'
this._cb = cb
this._rows = []
const msg = {
portal: this._portal,
rows: rows
rows: rows,
}
this.connection.execute(msg, true)
this.connection.flush()
}

Cursor.prototype.end = function (cb) {
Cursor.prototype.end = function(cb) {
if (this.state !== 'initialized') {
this.connection.sync()
}
this.connection.once('end', cb)
this.connection.end()
}

Cursor.prototype.close = function (cb) {
Cursor.prototype.close = function(cb) {
if (this.state === 'done') {
return setImmediate(cb)
}
this.connection.close({ type: 'P' })
this.connection.sync()
this.state = 'done'
if (cb) {
this.connection.once('closeComplete', function () {
this.connection.once('closeComplete', function() {
cb()
})
}
}

Cursor.prototype.read = function (rows, cb) {
Cursor.prototype.read = function(rows, cb) {
if (this.state === 'idle') {
return this._getRows(rows, cb)
}
Expand Down
Loading

0 comments on commit 414fac6

Please sign in to comment.