mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Apply prettier to code, change lint rules
This commit is contained in:
parent
1cdad4d8d2
commit
414fac6a05
12
.eslintrc
12
.eslintrc
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@ language: node_js
|
||||
dist: trusty
|
||||
sudo: false
|
||||
node_js:
|
||||
- "4.2"
|
||||
- "6"
|
||||
- "8"
|
||||
- "10"
|
||||
- "12"
|
||||
env:
|
||||
- PGUSER=postgres
|
||||
services:
|
||||
|
||||
5
Makefile
5
Makefile
@ -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
|
||||
|
||||
67
index.js
67
index.js
@ -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 || {}
|
||||
@ -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.parse(
|
||||
{
|
||||
text: this.text,
|
||||
},
|
||||
true
|
||||
)
|
||||
|
||||
con.bind({
|
||||
portal: this._portal,
|
||||
values: this.values
|
||||
}, 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.describe(
|
||||
{
|
||||
type: 'P',
|
||||
name: this._portal, // AWS Redshift requires a portal name
|
||||
},
|
||||
true
|
||||
)
|
||||
|
||||
con.flush()
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
@ -133,19 +142,19 @@ 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()
|
||||
}
|
||||
@ -153,7 +162,7 @@ Cursor.prototype.end = function (cb) {
|
||||
this.connection.end()
|
||||
}
|
||||
|
||||
Cursor.prototype.close = function (cb) {
|
||||
Cursor.prototype.close = function(cb) {
|
||||
if (this.state === 'done') {
|
||||
return setImmediate(cb)
|
||||
}
|
||||
@ -161,13 +170,13 @@ Cursor.prototype.close = function (cb) {
|
||||
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)
|
||||
}
|
||||
|
||||
1807
package-lock.json
generated
1807
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -16,14 +16,18 @@
|
||||
"author": "Brian M. Carlson",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint": "^4.4.0",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
"eslint": "^6.5.1",
|
||||
"eslint-config-prettier": "^6.4.0",
|
||||
"eslint-plugin-import": "^2.7.0",
|
||||
"eslint-plugin-node": "^5.1.1",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"mocha": "^3.5.0",
|
||||
"pg": "6.x"
|
||||
"eslint-plugin-prettier": "^3.1.1",
|
||||
"mocha": "^6.2.2",
|
||||
"pg": "^7.12.1",
|
||||
"prettier": "^1.18.2"
|
||||
},
|
||||
"dependencies": {}
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "es5",
|
||||
"singleQuote": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,30 +3,30 @@ var Cursor = require('../')
|
||||
var pg = require('pg')
|
||||
|
||||
var text = 'SELECT generate_series as num FROM generate_series(0, 50)'
|
||||
describe('close', function () {
|
||||
beforeEach(function (done) {
|
||||
var client = this.client = new pg.Client()
|
||||
describe('close', function() {
|
||||
beforeEach(function(done) {
|
||||
var client = (this.client = new pg.Client())
|
||||
client.connect(done)
|
||||
client.on('drain', client.end.bind(client))
|
||||
})
|
||||
|
||||
it('closes cursor early', function (done) {
|
||||
it('closes cursor early', function(done) {
|
||||
var cursor = new Cursor(text)
|
||||
this.client.query(cursor)
|
||||
this.client.query('SELECT NOW()', done)
|
||||
cursor.read(25, function (err, res) {
|
||||
cursor.read(25, function(err) {
|
||||
assert.ifError(err)
|
||||
cursor.close()
|
||||
})
|
||||
})
|
||||
|
||||
it('works with callback style', function (done) {
|
||||
it('works with callback style', function(done) {
|
||||
var cursor = new Cursor(text)
|
||||
var client = this.client
|
||||
client.query(cursor)
|
||||
cursor.read(25, function (err, res) {
|
||||
cursor.read(25, function(err) {
|
||||
assert.ifError(err)
|
||||
cursor.close(function (err) {
|
||||
cursor.close(function(err) {
|
||||
assert.ifError(err)
|
||||
client.query('SELECT NOW()', done)
|
||||
})
|
||||
|
||||
@ -5,14 +5,14 @@ var pg = require('pg')
|
||||
|
||||
var text = 'SELECT generate_series as num FROM generate_series(0, 4)'
|
||||
|
||||
describe('error handling', function () {
|
||||
it('can continue after error', function (done) {
|
||||
describe('error handling', function() {
|
||||
it('can continue after error', function(done) {
|
||||
var client = new pg.Client()
|
||||
client.connect()
|
||||
var cursor = client.query(new Cursor('asdfdffsdf'))
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(err)
|
||||
client.query('SELECT NOW()', function (err, res) {
|
||||
client.query('SELECT NOW()', function(err) {
|
||||
assert.ifError(err)
|
||||
client.end()
|
||||
done()
|
||||
@ -22,16 +22,16 @@ describe('error handling', function () {
|
||||
})
|
||||
|
||||
describe('read callback does not fire sync', () => {
|
||||
it('does not fire error callback sync', (done) => {
|
||||
it('does not fire error callback sync', done => {
|
||||
var client = new pg.Client()
|
||||
client.connect()
|
||||
var cursor = client.query(new Cursor('asdfdffsdf'))
|
||||
let after = false
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(err, 'error should be returned')
|
||||
assert.equal(after, true, 'should not call read sync')
|
||||
after = false
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(err, 'error should be returned')
|
||||
assert.equal(after, true, 'should not call read sync')
|
||||
client.end()
|
||||
@ -42,18 +42,18 @@ describe('read callback does not fire sync', () => {
|
||||
after = true
|
||||
})
|
||||
|
||||
it('does not fire result sync after finished', (done) => {
|
||||
it('does not fire result sync after finished', done => {
|
||||
var client = new pg.Client()
|
||||
client.connect()
|
||||
var cursor = client.query(new Cursor('SELECT NOW()'))
|
||||
let after = false
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(!err)
|
||||
assert.equal(after, true, 'should not call read sync')
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(!err)
|
||||
after = false
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(!err)
|
||||
assert.equal(after, true, 'should not call read sync')
|
||||
client.end()
|
||||
@ -66,16 +66,16 @@ describe('read callback does not fire sync', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('proper cleanup', function () {
|
||||
it('can issue multiple cursors on one client', function (done) {
|
||||
describe('proper cleanup', function() {
|
||||
it('can issue multiple cursors on one client', function(done) {
|
||||
var client = new pg.Client()
|
||||
client.connect()
|
||||
var cursor1 = client.query(new Cursor(text))
|
||||
cursor1.read(8, function (err, rows) {
|
||||
cursor1.read(8, function(err, rows) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 5)
|
||||
var cursor2 = client.query(new Cursor(text))
|
||||
cursor2.read(8, function (err, rows) {
|
||||
cursor2.read(8, function(err, rows) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 5)
|
||||
client.end()
|
||||
|
||||
@ -4,59 +4,59 @@ var pg = require('pg')
|
||||
|
||||
var text = 'SELECT generate_series as num FROM generate_series(0, 5)'
|
||||
|
||||
describe('cursor', function () {
|
||||
beforeEach(function (done) {
|
||||
var client = this.client = new pg.Client()
|
||||
describe('cursor', function() {
|
||||
beforeEach(function(done) {
|
||||
var client = (this.client = new pg.Client())
|
||||
client.connect(done)
|
||||
|
||||
this.pgCursor = function (text, values) {
|
||||
this.pgCursor = function(text, values) {
|
||||
client.on('drain', client.end.bind(client))
|
||||
return client.query(new Cursor(text, values || []))
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function() {
|
||||
this.client.end()
|
||||
})
|
||||
|
||||
it('fetch 6 when asking for 10', function (done) {
|
||||
it('fetch 6 when asking for 10', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(10, function (err, res) {
|
||||
cursor.read(10, function(err, res) {
|
||||
assert.ifError(err)
|
||||
assert.equal(res.length, 6)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('end before reading to end', function (done) {
|
||||
it('end before reading to end', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(3, function (err, res) {
|
||||
cursor.read(3, function(err, res) {
|
||||
assert.ifError(err)
|
||||
assert.equal(res.length, 3)
|
||||
cursor.end(done)
|
||||
})
|
||||
})
|
||||
|
||||
it('callback with error', function (done) {
|
||||
it('callback with error', function(done) {
|
||||
var cursor = this.pgCursor('select asdfasdf')
|
||||
cursor.read(1, function (err) {
|
||||
cursor.read(1, function(err) {
|
||||
assert(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('read a partial chunk of data', function (done) {
|
||||
it('read a partial chunk of data', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(2, function (err, res) {
|
||||
cursor.read(2, function(err, res) {
|
||||
assert.ifError(err)
|
||||
assert.equal(res.length, 2)
|
||||
cursor.read(3, function (err, res) {
|
||||
cursor.read(3, function(err, res) {
|
||||
assert(!err)
|
||||
assert.equal(res.length, 3)
|
||||
cursor.read(1, function (err, res) {
|
||||
cursor.read(1, function(err, res) {
|
||||
assert(!err)
|
||||
assert.equal(res.length, 1)
|
||||
cursor.read(1, function (err, res) {
|
||||
cursor.read(1, function(err, res) {
|
||||
assert(!err)
|
||||
assert.ifError(err)
|
||||
assert.strictEqual(res.length, 0)
|
||||
@ -67,14 +67,14 @@ describe('cursor', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('read return length 0 past the end', function (done) {
|
||||
it('read return length 0 past the end', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(2, function (err, res) {
|
||||
cursor.read(2, function(err) {
|
||||
assert(!err)
|
||||
cursor.read(100, function (err, res) {
|
||||
cursor.read(100, function(err, res) {
|
||||
assert(!err)
|
||||
assert.equal(res.length, 4)
|
||||
cursor.read(100, function (err, res) {
|
||||
cursor.read(100, function(err, res) {
|
||||
assert(!err)
|
||||
assert.equal(res.length, 0)
|
||||
done()
|
||||
@ -83,14 +83,14 @@ describe('cursor', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('read huge result', function (done) {
|
||||
it('read huge result', function(done) {
|
||||
this.timeout(10000)
|
||||
var text = 'SELECT generate_series as num FROM generate_series(0, 100000)'
|
||||
var values = []
|
||||
var cursor = this.pgCursor(text, values)
|
||||
var count = 0
|
||||
var read = function () {
|
||||
cursor.read(100, function (err, rows) {
|
||||
var read = function() {
|
||||
cursor.read(100, function(err, rows) {
|
||||
if (err) return done(err)
|
||||
if (!rows.length) {
|
||||
assert.equal(count, 100001)
|
||||
@ -106,14 +106,14 @@ describe('cursor', function () {
|
||||
read()
|
||||
})
|
||||
|
||||
it('normalizes parameter values', function (done) {
|
||||
it('normalizes parameter values', function(done) {
|
||||
var text = 'SELECT $1::json me'
|
||||
var values = [{ name: 'brian' }]
|
||||
var cursor = this.pgCursor(text, values)
|
||||
cursor.read(1, function (err, rows) {
|
||||
cursor.read(1, function(err, rows) {
|
||||
if (err) return done(err)
|
||||
assert.equal(rows[0].me.name, 'brian')
|
||||
cursor.read(1, function (err, rows) {
|
||||
cursor.read(1, function(err, rows) {
|
||||
assert(!err)
|
||||
assert.equal(rows.length, 0)
|
||||
done()
|
||||
@ -121,9 +121,9 @@ describe('cursor', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('returns result along with rows', function (done) {
|
||||
it('returns result along with rows', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(1, function (err, rows, result) {
|
||||
cursor.read(1, function(err, rows, result) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 1)
|
||||
assert.strictEqual(rows, result.rows)
|
||||
@ -132,20 +132,20 @@ describe('cursor', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('emits row events', function (done) {
|
||||
it('emits row events', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.read(10)
|
||||
cursor.on('row', (row, result) => result.addRow(row))
|
||||
cursor.on('end', (result) => {
|
||||
cursor.on('end', result => {
|
||||
assert.equal(result.rows.length, 6)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('emits row events when cursor is closed manually', function (done) {
|
||||
it('emits row events when cursor is closed manually', function(done) {
|
||||
var cursor = this.pgCursor(text)
|
||||
cursor.on('row', (row, result) => result.addRow(row))
|
||||
cursor.on('end', (result) => {
|
||||
cursor.on('end', result => {
|
||||
assert.equal(result.rows.length, 3)
|
||||
done()
|
||||
})
|
||||
@ -153,25 +153,27 @@ describe('cursor', function () {
|
||||
cursor.read(3, () => cursor.close())
|
||||
})
|
||||
|
||||
it('emits error events', function (done) {
|
||||
it('emits error events', function(done) {
|
||||
var cursor = this.pgCursor('select asdfasdf')
|
||||
cursor.on('error', function (err) {
|
||||
cursor.on('error', function(err) {
|
||||
assert(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('returns rowCount on insert', function (done) {
|
||||
it('returns rowCount on insert', function(done) {
|
||||
var pgCursor = this.pgCursor
|
||||
this.client.query('CREATE TEMPORARY TABLE pg_cursor_test (foo VARCHAR(1), bar VARCHAR(1))')
|
||||
.then(function () {
|
||||
this.client
|
||||
.query('CREATE TEMPORARY TABLE pg_cursor_test (foo VARCHAR(1), bar VARCHAR(1))')
|
||||
.then(function() {
|
||||
var cursor = pgCursor('insert into pg_cursor_test values($1, $2)', ['a', 'b'])
|
||||
cursor.read(1, function (err, rows, result) {
|
||||
cursor.read(1, function(err, rows, result) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 0)
|
||||
assert.equal(result.rowCount, 1)
|
||||
done()
|
||||
})
|
||||
}).catch(done)
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
})
|
||||
|
||||
@ -2,30 +2,30 @@ var assert = require('assert')
|
||||
var pg = require('pg')
|
||||
var Cursor = require('../')
|
||||
|
||||
describe('queries with no data', function () {
|
||||
beforeEach(function (done) {
|
||||
var client = this.client = new pg.Client()
|
||||
describe('queries with no data', function() {
|
||||
beforeEach(function(done) {
|
||||
var client = (this.client = new pg.Client())
|
||||
client.connect(done)
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function() {
|
||||
this.client.end()
|
||||
})
|
||||
|
||||
it('handles queries that return no data', function (done) {
|
||||
it('handles queries that return no data', function(done) {
|
||||
var cursor = new Cursor('CREATE TEMPORARY TABLE whatwhat (thing int)')
|
||||
this.client.query(cursor)
|
||||
cursor.read(100, function (err, rows) {
|
||||
cursor.read(100, function(err, rows) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 0)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('handles empty query', function (done) {
|
||||
it('handles empty query', function(done) {
|
||||
var cursor = new Cursor('-- this is a comment')
|
||||
cursor = this.client.query(cursor)
|
||||
cursor.read(100, function (err, rows) {
|
||||
cursor.read(100, function(err, rows) {
|
||||
assert.ifError(err)
|
||||
assert.equal(rows.length, 0)
|
||||
done()
|
||||
|
||||
20
test/pool.js
20
test/pool.js
@ -5,7 +5,7 @@ const pg = require('pg')
|
||||
|
||||
const text = 'SELECT generate_series as num FROM generate_series(0, 50)'
|
||||
|
||||
function poolQueryPromise (pool, readRowCount) {
|
||||
function poolQueryPromise(pool, readRowCount) {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.connect((err, client, done) => {
|
||||
if (err) {
|
||||
@ -13,7 +13,7 @@ function poolQueryPromise (pool, readRowCount) {
|
||||
return reject(err)
|
||||
}
|
||||
const cursor = client.query(new Cursor(text))
|
||||
cursor.read(readRowCount, (err, res) => {
|
||||
cursor.read(readRowCount, err => {
|
||||
if (err) {
|
||||
done(err)
|
||||
return reject(err)
|
||||
@ -31,16 +31,16 @@ function poolQueryPromise (pool, readRowCount) {
|
||||
})
|
||||
}
|
||||
|
||||
describe('pool', function () {
|
||||
beforeEach(function () {
|
||||
this.pool = new pg.Pool({max: 1})
|
||||
describe('pool', function() {
|
||||
beforeEach(function() {
|
||||
this.pool = new pg.Pool({ max: 1 })
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function() {
|
||||
this.pool.end()
|
||||
})
|
||||
|
||||
it('closes cursor early, single pool query', function (done) {
|
||||
it('closes cursor early, single pool query', function(done) {
|
||||
poolQueryPromise(this.pool, 25)
|
||||
.then(() => done())
|
||||
.catch(err => {
|
||||
@ -49,7 +49,7 @@ describe('pool', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('closes cursor early, saturated pool', function (done) {
|
||||
it('closes cursor early, saturated pool', function(done) {
|
||||
const promises = []
|
||||
for (let i = 0; i < 10; i++) {
|
||||
promises.push(poolQueryPromise(this.pool, 25))
|
||||
@ -62,7 +62,7 @@ describe('pool', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('closes exhausted cursor, single pool query', function (done) {
|
||||
it('closes exhausted cursor, single pool query', function(done) {
|
||||
poolQueryPromise(this.pool, 100)
|
||||
.then(() => done())
|
||||
.catch(err => {
|
||||
@ -71,7 +71,7 @@ describe('pool', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('closes exhausted cursor, saturated pool', function (done) {
|
||||
it('closes exhausted cursor, saturated pool', function(done) {
|
||||
const promises = []
|
||||
for (let i = 0; i < 10; i++) {
|
||||
promises.push(poolQueryPromise(this.pool, 100))
|
||||
|
||||
@ -4,7 +4,7 @@ const Cursor = require('../')
|
||||
const pg = require('pg')
|
||||
|
||||
describe('query config passed to result', () => {
|
||||
it('passes rowMode to result', (done) => {
|
||||
it('passes rowMode to result', done => {
|
||||
const client = new pg.Client()
|
||||
client.connect()
|
||||
const text = 'SELECT generate_series as num FROM generate_series(0, 5)'
|
||||
@ -17,12 +17,12 @@ describe('query config passed to result', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('passes types to result', (done) => {
|
||||
it('passes types to result', done => {
|
||||
const client = new pg.Client()
|
||||
client.connect()
|
||||
const text = 'SELECT generate_series as num FROM generate_series(0, 2)'
|
||||
const types = {
|
||||
getTypeParser: () => () => 'foo'
|
||||
getTypeParser: () => () => 'foo',
|
||||
}
|
||||
const cursor = client.query(new Cursor(text, null, { types }))
|
||||
cursor.read(10, (err, rows) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user