pg 8.0.2 → 8.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -37,7 +37,7 @@ var Client = function (config) {
37
37
  configurable: true,
38
38
  enumerable: false,
39
39
  writable: true,
40
- value: this.connectionParameters.password
40
+ value: this.connectionParameters.password,
41
41
  })
42
42
 
43
43
  this.replication = this.connectionParameters.replication
@@ -52,13 +52,15 @@ var Client = function (config) {
52
52
  this._connectionError = false
53
53
  this._queryable = true
54
54
 
55
- this.connection = c.connection || new Connection({
56
- stream: c.stream,
57
- ssl: this.connectionParameters.ssl,
58
- keepAlive: c.keepAlive || false,
59
- keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
60
- encoding: this.connectionParameters.client_encoding || 'utf8'
61
- })
55
+ this.connection =
56
+ c.connection ||
57
+ new Connection({
58
+ stream: c.stream,
59
+ ssl: this.connectionParameters.ssl,
60
+ keepAlive: c.keepAlive || false,
61
+ keepAliveInitialDelayMillis: c.keepAliveInitialDelayMillis || 0,
62
+ encoding: this.connectionParameters.client_encoding || 'utf8',
63
+ })
62
64
  this.queryQueue = []
63
65
  this.binary = c.binary || defaults.binary
64
66
  this.processID = null
@@ -127,9 +129,10 @@ Client.prototype._connect = function (callback) {
127
129
  function checkPgPass(cb) {
128
130
  return function (msg) {
129
131
  if (typeof self.password === 'function') {
130
- self._Promise.resolve()
132
+ self._Promise
133
+ .resolve()
131
134
  .then(() => self.password())
132
- .then(pass => {
135
+ .then((pass) => {
133
136
  if (pass !== undefined) {
134
137
  if (typeof pass !== 'string') {
135
138
  con.emit('error', new TypeError('Password must be a string'))
@@ -140,7 +143,8 @@ Client.prototype._connect = function (callback) {
140
143
  self.connectionParameters.password = self.password = null
141
144
  }
142
145
  cb(msg)
143
- }).catch(err => {
146
+ })
147
+ .catch((err) => {
144
148
  con.emit('error', err)
145
149
  })
146
150
  } else if (self.password !== null) {
@@ -157,22 +161,31 @@ Client.prototype._connect = function (callback) {
157
161
  }
158
162
 
159
163
  // password request handling
160
- con.on('authenticationCleartextPassword', checkPgPass(function () {
161
- con.password(self.password)
162
- }))
164
+ con.on(
165
+ 'authenticationCleartextPassword',
166
+ checkPgPass(function () {
167
+ con.password(self.password)
168
+ })
169
+ )
163
170
 
164
171
  // password request handling
165
- con.on('authenticationMD5Password', checkPgPass(function (msg) {
166
- con.password(utils.postgresMd5PasswordHash(self.user, self.password, msg.salt))
167
- }))
172
+ con.on(
173
+ 'authenticationMD5Password',
174
+ checkPgPass(function (msg) {
175
+ con.password(utils.postgresMd5PasswordHash(self.user, self.password, msg.salt))
176
+ })
177
+ )
168
178
 
169
179
  // password request handling (SASL)
170
180
  var saslSession
171
- con.on('authenticationSASL', checkPgPass(function (msg) {
172
- saslSession = sasl.startSession(msg.mechanisms)
181
+ con.on(
182
+ 'authenticationSASL',
183
+ checkPgPass(function (msg) {
184
+ saslSession = sasl.startSession(msg.mechanisms)
173
185
 
174
- con.sendSASLInitialResponseMessage(saslSession.mechanism, saslSession.response)
175
- }))
186
+ con.sendSASLInitialResponseMessage(saslSession.mechanism, saslSession.response)
187
+ })
188
+ )
176
189
 
177
190
  // password request handling (SASL)
178
191
  con.on('authenticationSASLContinue', function (msg) {
@@ -259,9 +272,7 @@ Client.prototype._connect = function (callback) {
259
272
  })
260
273
 
261
274
  con.once('end', () => {
262
- const error = this._ending
263
- ? new Error('Connection terminated')
264
- : new Error('Connection terminated unexpectedly')
275
+ const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')
265
276
 
266
277
  clearTimeout(connectionTimeoutHandle)
267
278
  this._errorAllQueries(error)
@@ -367,7 +378,7 @@ Client.prototype.getStartupConf = function () {
367
378
 
368
379
  var data = {
369
380
  user: params.user,
370
- database: params.database
381
+ database: params.database,
371
382
  }
372
383
 
373
384
  var appName = params.application_name || params.fallback_application_name
@@ -422,11 +433,11 @@ Client.prototype.escapeIdentifier = function (str) {
422
433
  // Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
423
434
  Client.prototype.escapeLiteral = function (str) {
424
435
  var hasBackslash = false
425
- var escaped = '\''
436
+ var escaped = "'"
426
437
 
427
438
  for (var i = 0; i < str.length; i++) {
428
439
  var c = str[i]
429
- if (c === '\'') {
440
+ if (c === "'") {
430
441
  escaped += c + c
431
442
  } else if (c === '\\') {
432
443
  escaped += c + c
@@ -436,7 +447,7 @@ Client.prototype.escapeLiteral = function (str) {
436
447
  }
437
448
  }
438
449
 
439
- escaped += '\''
450
+ escaped += "'"
440
451
 
441
452
  if (hasBackslash === true) {
442
453
  escaped = ' E' + escaped
@@ -488,7 +499,7 @@ Client.prototype.query = function (config, values, callback) {
488
499
  query = new Query(config, values, callback)
489
500
  if (!query.callback) {
490
501
  result = new this._Promise((resolve, reject) => {
491
- query.callback = (err, res) => err ? reject(err) : resolve(res)
502
+ query.callback = (err, res) => (err ? reject(err) : resolve(res))
492
503
  })
493
504
  }
494
505
  }
@@ -507,7 +518,7 @@ Client.prototype.query = function (config, values, callback) {
507
518
 
508
519
  // we already returned an error,
509
520
  // just do nothing if query completes
510
- query.callback = () => { }
521
+ query.callback = () => {}
511
522
 
512
523
  // Remove from queue
513
524
  var index = this.queryQueue.indexOf(query)
@@ -555,7 +566,7 @@ Client.prototype.end = function (cb) {
555
566
  this._ending = true
556
567
 
557
568
  // if we have never connected, then end is a noop, callback immediately
558
- if (this.connection.stream.readyState === 'closed') {
569
+ if (!this.connection._connecting) {
559
570
  if (cb) {
560
571
  cb()
561
572
  } else {
@@ -42,13 +42,10 @@ util.inherits(Connection, EventEmitter)
42
42
  Connection.prototype.connect = function (port, host) {
43
43
  var self = this
44
44
 
45
- if (this.stream.readyState === 'closed') {
46
- this.stream.connect(port, host)
47
- } else if (this.stream.readyState === 'open') {
48
- this.emit('connect')
49
- }
45
+ this._connecting = true
46
+ this.stream.connect(port, host)
50
47
 
51
- this.stream.on('connect', function () {
48
+ this.stream.once('connect', function () {
52
49
  if (self._keepAlive) {
53
50
  self.stream.setKeepAlive(true, self._keepAliveInitialDelayMillis)
54
51
  }
@@ -80,14 +77,18 @@ Connection.prototype.connect = function (port, host) {
80
77
  case 'N': // Server does not support SSL connections
81
78
  self.stream.end()
82
79
  return self.emit('error', new Error('The server does not support SSL connections'))
83
- default: // Any other response byte, including 'E' (ErrorResponse) indicating a server error
80
+ default:
81
+ // Any other response byte, including 'E' (ErrorResponse) indicating a server error
84
82
  self.stream.end()
85
83
  return self.emit('error', new Error('There was an error establishing an SSL connection'))
86
84
  }
87
85
  var tls = require('tls')
88
- const options = Object.assign({
89
- socket: self.stream
90
- }, self.ssl)
86
+ const options = Object.assign(
87
+ {
88
+ socket: self.stream,
89
+ },
90
+ self.ssl
91
+ )
91
92
  if (net.isIP(host) === 0) {
92
93
  options.servername = host
93
94
  }
@@ -183,7 +184,7 @@ const endBuffer = serialize.end()
183
184
  Connection.prototype.end = function () {
184
185
  // 0x58 = 'X'
185
186
  this._ending = true
186
- if (!this.stream.writable) {
187
+ if (!this._connecting || !this.stream.writable) {
187
188
  this.stream.end()
188
189
  return
189
190
  }
@@ -22,9 +22,7 @@ var val = function (key, config, envVar) {
22
22
  envVar = process.env[envVar]
23
23
  }
24
24
 
25
- return config[key] ||
26
- envVar ||
27
- defaults[key]
25
+ return config[key] || envVar || defaults[key]
28
26
  }
29
27
 
30
28
  var useSsl = function () {
@@ -66,7 +64,7 @@ var ConnectionParameters = function (config) {
66
64
  configurable: true,
67
65
  enumerable: false,
68
66
  writable: true,
69
- value: val('password', config)
67
+ value: val('password', config),
70
68
  })
71
69
 
72
70
  this.binary = val('binary', config)
@@ -74,7 +72,7 @@ var ConnectionParameters = function (config) {
74
72
  this.client_encoding = val('client_encoding', config)
75
73
  this.replication = val('replication', config)
76
74
  // a domain socket begins with '/'
77
- this.isDomainSocket = (!(this.host || '').indexOf('/'))
75
+ this.isDomainSocket = !(this.host || '').indexOf('/')
78
76
 
79
77
  this.application_name = val('application_name', config, 'PGAPPNAME')
80
78
  this.fallback_application_name = val('fallback_application_name', config, false)
package/lib/connection.js CHANGED
@@ -35,7 +35,7 @@ var Connection = function (config) {
35
35
  this._emitMessage = false
36
36
  this._reader = new Reader({
37
37
  headerSize: 1,
38
- lengthPadding: -4
38
+ lengthPadding: -4,
39
39
  })
40
40
  var self = this
41
41
  this.on('newListener', function (eventName) {
@@ -50,13 +50,10 @@ util.inherits(Connection, EventEmitter)
50
50
  Connection.prototype.connect = function (port, host) {
51
51
  var self = this
52
52
 
53
- if (this.stream.readyState === 'closed') {
54
- this.stream.connect(port, host)
55
- } else if (this.stream.readyState === 'open') {
56
- this.emit('connect')
57
- }
53
+ this._connecting = true
54
+ this.stream.connect(port, host)
58
55
 
59
- this.stream.on('connect', function () {
56
+ this.stream.once('connect', function () {
60
57
  if (self._keepAlive) {
61
58
  self.stream.setKeepAlive(true, self._keepAliveInitialDelayMillis)
62
59
  }
@@ -88,14 +85,18 @@ Connection.prototype.connect = function (port, host) {
88
85
  case 'N': // Server does not support SSL connections
89
86
  self.stream.end()
90
87
  return self.emit('error', new Error('The server does not support SSL connections'))
91
- default: // Any other response byte, including 'E' (ErrorResponse) indicating a server error
88
+ default:
89
+ // Any other response byte, including 'E' (ErrorResponse) indicating a server error
92
90
  self.stream.end()
93
91
  return self.emit('error', new Error('There was an error establishing an SSL connection'))
94
92
  }
95
93
  var tls = require('tls')
96
- const options = Object.assign({
97
- socket: self.stream
98
- }, self.ssl)
94
+ const options = Object.assign(
95
+ {
96
+ socket: self.stream,
97
+ },
98
+ self.ssl
99
+ )
99
100
  if (net.isIP(host) === 0) {
100
101
  options.servername = host
101
102
  }
@@ -127,23 +128,16 @@ Connection.prototype.attachListeners = function (stream) {
127
128
  }
128
129
 
129
130
  Connection.prototype.requestSsl = function () {
130
- var bodyBuffer = this.writer
131
- .addInt16(0x04D2)
132
- .addInt16(0x162F).flush()
131
+ var bodyBuffer = this.writer.addInt16(0x04d2).addInt16(0x162f).flush()
133
132
 
134
133
  var length = bodyBuffer.length + 4
135
134
 
136
- var buffer = new Writer()
137
- .addInt32(length)
138
- .add(bodyBuffer)
139
- .join()
135
+ var buffer = new Writer().addInt32(length).add(bodyBuffer).join()
140
136
  this.stream.write(buffer)
141
137
  }
142
138
 
143
139
  Connection.prototype.startup = function (config) {
144
- var writer = this.writer
145
- .addInt16(3)
146
- .addInt16(0)
140
+ var writer = this.writer.addInt16(3).addInt16(0)
147
141
 
148
142
  Object.keys(config).forEach(function (key) {
149
143
  var val = config[key]
@@ -157,27 +151,16 @@ Connection.prototype.startup = function (config) {
157
151
 
158
152
  var length = bodyBuffer.length + 4
159
153
 
160
- var buffer = new Writer()
161
- .addInt32(length)
162
- .add(bodyBuffer)
163
- .join()
154
+ var buffer = new Writer().addInt32(length).add(bodyBuffer).join()
164
155
  this.stream.write(buffer)
165
156
  }
166
157
 
167
158
  Connection.prototype.cancel = function (processID, secretKey) {
168
- var bodyBuffer = this.writer
169
- .addInt16(1234)
170
- .addInt16(5678)
171
- .addInt32(processID)
172
- .addInt32(secretKey)
173
- .flush()
159
+ var bodyBuffer = this.writer.addInt16(1234).addInt16(5678).addInt32(processID).addInt32(secretKey).flush()
174
160
 
175
161
  var length = bodyBuffer.length + 4
176
162
 
177
- var buffer = new Writer()
178
- .addInt32(length)
179
- .add(bodyBuffer)
180
- .join()
163
+ var buffer = new Writer().addInt32(length).add(bodyBuffer).join()
181
164
  this.stream.write(buffer)
182
165
  }
183
166
 
@@ -188,18 +171,14 @@ Connection.prototype.password = function (password) {
188
171
 
189
172
  Connection.prototype.sendSASLInitialResponseMessage = function (mechanism, initialResponse) {
190
173
  // 0x70 = 'p'
191
- this.writer
192
- .addCString(mechanism)
193
- .addInt32(Buffer.byteLength(initialResponse))
194
- .addString(initialResponse)
174
+ this.writer.addCString(mechanism).addInt32(Buffer.byteLength(initialResponse)).addString(initialResponse)
195
175
 
196
176
  this._send(0x70)
197
177
  }
198
178
 
199
179
  Connection.prototype.sendSCRAMClientFinalMessage = function (additionalData) {
200
180
  // 0x70 = 'p'
201
- this.writer
202
- .addString(additionalData)
181
+ this.writer.addString(additionalData)
203
182
 
204
183
  this._send(0x70)
205
184
  }
@@ -263,13 +242,17 @@ Connection.prototype.bind = function (config, more) {
263
242
  var values = config.values || []
264
243
  var len = values.length
265
244
  var useBinary = false
266
- for (var j = 0; j < len; j++) { useBinary |= values[j] instanceof Buffer }
267
- var buffer = this.writer
268
- .addCString(config.portal)
269
- .addCString(config.statement)
270
- if (!useBinary) { buffer.addInt16(0) } else {
245
+ for (var j = 0; j < len; j++) {
246
+ useBinary |= values[j] instanceof Buffer
247
+ }
248
+ var buffer = this.writer.addCString(config.portal).addCString(config.statement)
249
+ if (!useBinary) {
250
+ buffer.addInt16(0)
251
+ } else {
271
252
  buffer.addInt16(len)
272
- for (j = 0; j < len; j++) { buffer.addInt16(values[j] instanceof Buffer) }
253
+ for (j = 0; j < len; j++) {
254
+ buffer.addInt16(values[j] instanceof Buffer)
255
+ }
273
256
  }
274
257
  buffer.addInt16(len)
275
258
  for (var i = 0; i < len; i++) {
@@ -301,9 +284,7 @@ Connection.prototype.execute = function (config, more) {
301
284
  config = config || {}
302
285
  config.portal = config.portal || ''
303
286
  config.rows = config.rows || ''
304
- this.writer
305
- .addCString(config.portal)
306
- .addInt32(config.rows)
287
+ this.writer.addCString(config.portal).addInt32(config.rows)
307
288
 
308
289
  // 0x45 = 'E'
309
290
  this._send(0x45, more)
@@ -332,7 +313,7 @@ Connection.prototype.end = function () {
332
313
  // 0x58 = 'X'
333
314
  this.writer.add(emptyBuffer)
334
315
  this._ending = true
335
- if (!this.stream.writable) {
316
+ if (!this._connecting || !this.stream.writable) {
336
317
  this.stream.end()
337
318
  return
338
319
  }
package/lib/defaults.js CHANGED
@@ -70,7 +70,7 @@ module.exports = {
70
70
 
71
71
  keepalives: 1,
72
72
 
73
- keepalives_idle: 0
73
+ keepalives_idle: 0,
74
74
  }
75
75
 
76
76
  var pgTypes = require('pg-types')
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var Pool = require('pg-pool')
14
14
 
15
15
  const poolFactory = (Client) => {
16
16
  return class BoundPool extends Pool {
17
- constructor (options) {
17
+ constructor(options) {
18
18
  super(options, Client)
19
19
  }
20
20
  }
@@ -54,10 +54,10 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
54
54
 
55
55
  // overwrite module.exports.native so that getter is never called again
56
56
  Object.defineProperty(module.exports, 'native', {
57
- value: native
57
+ value: native,
58
58
  })
59
59
 
60
60
  return native
61
- }
61
+ },
62
62
  })
63
63
  }
@@ -22,7 +22,7 @@ assert(semver.gte(Native.version, pkg.minNativeVersion), msg)
22
22
 
23
23
  var NativeQuery = require('./query')
24
24
 
25
- var Client = module.exports = function (config) {
25
+ var Client = (module.exports = function (config) {
26
26
  EventEmitter.call(this)
27
27
  config = config || {}
28
28
 
@@ -30,7 +30,7 @@ var Client = module.exports = function (config) {
30
30
  this._types = new TypeOverrides(config.types)
31
31
 
32
32
  this.native = new Native({
33
- types: this._types
33
+ types: this._types,
34
34
  })
35
35
 
36
36
  this._queryQueue = []
@@ -41,7 +41,7 @@ var Client = module.exports = function (config) {
41
41
 
42
42
  // keep these on the object for legacy reasons
43
43
  // for the time being. TODO: deprecate all this jazz
44
- var cp = this.connectionParameters = new ConnectionParameters(config)
44
+ var cp = (this.connectionParameters = new ConnectionParameters(config))
45
45
  this.user = cp.user
46
46
 
47
47
  // "hiding" the password so it doesn't show up in stack traces
@@ -50,7 +50,7 @@ var Client = module.exports = function (config) {
50
50
  configurable: true,
51
51
  enumerable: false,
52
52
  writable: true,
53
- value: cp.password
53
+ value: cp.password,
54
54
  })
55
55
  this.database = cp.database
56
56
  this.host = cp.host
@@ -58,7 +58,7 @@ var Client = module.exports = function (config) {
58
58
 
59
59
  // a hash to hold named queries
60
60
  this.namedQueries = {}
61
- }
61
+ })
62
62
 
63
63
  Client.Query = NativeQuery
64
64
 
@@ -115,7 +115,7 @@ Client.prototype._connect = function (cb) {
115
115
  self.native.on('notification', function (msg) {
116
116
  self.emit('notification', {
117
117
  channel: msg.relname,
118
- payload: msg.extra
118
+ payload: msg.extra,
119
119
  })
120
120
  })
121
121
 
@@ -180,7 +180,7 @@ Client.prototype.query = function (config, values, callback) {
180
180
  resolveOut = resolve
181
181
  rejectOut = reject
182
182
  })
183
- query.callback = (err, res) => err ? rejectOut(err) : resolveOut(res)
183
+ query.callback = (err, res) => (err ? rejectOut(err) : resolveOut(res))
184
184
  }
185
185
  }
186
186
 
@@ -248,7 +248,7 @@ Client.prototype.end = function (cb) {
248
248
  var result
249
249
  if (!cb) {
250
250
  result = new this._Promise(function (resolve, reject) {
251
- cb = (err) => err ? reject(err) : resolve()
251
+ cb = (err) => (err ? reject(err) : resolve())
252
252
  })
253
253
  }
254
254
  this.native.end(function () {
@@ -11,7 +11,7 @@ var EventEmitter = require('events').EventEmitter
11
11
  var util = require('util')
12
12
  var utils = require('../utils')
13
13
 
14
- var NativeQuery = module.exports = function (config, values, callback) {
14
+ var NativeQuery = (module.exports = function (config, values, callback) {
15
15
  EventEmitter.call(this)
16
16
  config = utils.normalizeQueryConfig(config, values, callback)
17
17
  this.text = config.text
@@ -27,27 +27,30 @@ var NativeQuery = module.exports = function (config, values, callback) {
27
27
  // this has almost no meaning because libpq
28
28
  // reads all rows into memory befor returning any
29
29
  this._emitRowEvents = false
30
- this.on('newListener', function (event) {
31
- if (event === 'row') this._emitRowEvents = true
32
- }.bind(this))
33
- }
30
+ this.on(
31
+ 'newListener',
32
+ function (event) {
33
+ if (event === 'row') this._emitRowEvents = true
34
+ }.bind(this)
35
+ )
36
+ })
34
37
 
35
38
  util.inherits(NativeQuery, EventEmitter)
36
39
 
37
40
  var errorFieldMap = {
38
41
  /* eslint-disable quote-props */
39
- 'sqlState': 'code',
40
- 'statementPosition': 'position',
41
- 'messagePrimary': 'message',
42
- 'context': 'where',
43
- 'schemaName': 'schema',
44
- 'tableName': 'table',
45
- 'columnName': 'column',
46
- 'dataTypeName': 'dataType',
47
- 'constraintName': 'constraint',
48
- 'sourceFile': 'file',
49
- 'sourceLine': 'line',
50
- 'sourceFunction': 'routine'
42
+ sqlState: 'code',
43
+ statementPosition: 'position',
44
+ messagePrimary: 'message',
45
+ context: 'where',
46
+ schemaName: 'schema',
47
+ tableName: 'table',
48
+ columnName: 'column',
49
+ dataTypeName: 'dataType',
50
+ constraintName: 'constraint',
51
+ sourceFile: 'file',
52
+ sourceLine: 'line',
53
+ sourceFunction: 'routine',
51
54
  }
52
55
 
53
56
  NativeQuery.prototype.handleError = function (err) {
@@ -77,10 +80,12 @@ NativeQuery.prototype.catch = function (callback) {
77
80
 
78
81
  NativeQuery.prototype._getPromise = function () {
79
82
  if (this._promise) return this._promise
80
- this._promise = new Promise(function (resolve, reject) {
81
- this._once('end', resolve)
82
- this._once('error', reject)
83
- }.bind(this))
83
+ this._promise = new Promise(
84
+ function (resolve, reject) {
85
+ this._once('end', resolve)
86
+ this._once('error', reject)
87
+ }.bind(this)
88
+ )
84
89
  return this._promise
85
90
  }
86
91
 
@@ -105,7 +110,7 @@ NativeQuery.prototype.submit = function (client) {
105
110
  if (self._emitRowEvents) {
106
111
  if (results.length > 1) {
107
112
  rows.forEach((rowOfRows, i) => {
108
- rowOfRows.forEach(row => {
113
+ rowOfRows.forEach((row) => {
109
114
  self.emit('row', row, results[i])
110
115
  })
111
116
  })
package/lib/query.js CHANGED
@@ -42,14 +42,22 @@ class Query extends EventEmitter {
42
42
 
43
43
  requiresPreparation() {
44
44
  // named queries must always be prepared
45
- if (this.name) { return true }
45
+ if (this.name) {
46
+ return true
47
+ }
46
48
  // always prepare if there are max number of rows expected per
47
49
  // portal execution
48
- if (this.rows) { return true }
50
+ if (this.rows) {
51
+ return true
52
+ }
49
53
  // don't prepare empty text queries
50
- if (!this.text) { return false }
54
+ if (!this.text) {
55
+ return false
56
+ }
51
57
  // prepare if there are values
52
- if (!this.values) { return false }
58
+ if (!this.values) {
59
+ return false
60
+ }
53
61
  return this.values.length > 0
54
62
  }
55
63
 
@@ -168,10 +176,13 @@ class Query extends EventEmitter {
168
176
  }
169
177
 
170
178
  _getRows(connection, rows) {
171
- connection.execute({
172
- portal: this.portal,
173
- rows: rows
174
- }, true)
179
+ connection.execute(
180
+ {
181
+ portal: this.portal,
182
+ rows: rows,
183
+ },
184
+ true
185
+ )
175
186
  connection.flush()
176
187
  }
177
188
 
@@ -181,11 +192,14 @@ class Query extends EventEmitter {
181
192
  this.isPreparedStatement = true
182
193
  // TODO refactor this poor encapsulation
183
194
  if (!this.hasBeenParsed(connection)) {
184
- connection.parse({
185
- text: this.text,
186
- name: this.name,
187
- types: this.types
188
- }, true)
195
+ connection.parse(
196
+ {
197
+ text: this.text,
198
+ name: this.name,
199
+ types: this.types,
200
+ },
201
+ true
202
+ )
189
203
  }
190
204
 
191
205
  if (this.values) {
@@ -198,17 +212,23 @@ class Query extends EventEmitter {
198
212
  }
199
213
 
200
214
  // http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
201
- connection.bind({
202
- portal: this.portal,
203
- statement: this.name,
204
- values: this.values,
205
- binary: this.binary
206
- }, true)
207
-
208
- connection.describe({
209
- type: 'P',
210
- name: this.portal || ''
211
- }, true)
215
+ connection.bind(
216
+ {
217
+ portal: this.portal,
218
+ statement: this.name,
219
+ values: this.values,
220
+ binary: this.binary,
221
+ },
222
+ true
223
+ )
224
+
225
+ connection.describe(
226
+ {
227
+ type: 'P',
228
+ name: this.portal || '',
229
+ },
230
+ true
231
+ )
212
232
 
213
233
  this._getRows(connection, this.rows)
214
234
  }
package/lib/sasl.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
  const crypto = require('crypto')
3
3
 
4
- function startSession (mechanisms) {
4
+ function startSession(mechanisms) {
5
5
  if (mechanisms.indexOf('SCRAM-SHA-256') === -1) {
6
6
  throw new Error('SASL: Only mechanism SCRAM-SHA-256 is currently supported')
7
7
  }
@@ -12,11 +12,11 @@ function startSession (mechanisms) {
12
12
  mechanism: 'SCRAM-SHA-256',
13
13
  clientNonce,
14
14
  response: 'n,,n=*,r=' + clientNonce,
15
- message: 'SASLInitialResponse'
15
+ message: 'SASLInitialResponse',
16
16
  }
17
17
  }
18
18
 
19
- function continueSession (session, password, serverData) {
19
+ function continueSession(session, password, serverData) {
20
20
  if (session.message !== 'SASLInitialResponse') {
21
21
  throw new Error('SASL: Last message was not SASLInitialResponse')
22
22
  }
@@ -53,42 +53,46 @@ function continueSession (session, password, serverData) {
53
53
  session.response = clientFinalMessageWithoutProof + ',p=' + clientProof
54
54
  }
55
55
 
56
- function finalizeSession (session, serverData) {
56
+ function finalizeSession(session, serverData) {
57
57
  if (session.message !== 'SASLResponse') {
58
58
  throw new Error('SASL: Last message was not SASLResponse')
59
59
  }
60
60
 
61
61
  var serverSignature
62
62
 
63
- String(serverData).split(',').forEach(function (part) {
64
- switch (part[0]) {
65
- case 'v':
66
- serverSignature = part.substr(2)
67
- break
68
- }
69
- })
63
+ String(serverData)
64
+ .split(',')
65
+ .forEach(function (part) {
66
+ switch (part[0]) {
67
+ case 'v':
68
+ serverSignature = part.substr(2)
69
+ break
70
+ }
71
+ })
70
72
 
71
73
  if (serverSignature !== session.serverSignature) {
72
74
  throw new Error('SASL: SCRAM-SERVER-FINAL-MESSAGE: server signature does not match')
73
75
  }
74
76
  }
75
77
 
76
- function extractVariablesFromFirstServerMessage (data) {
78
+ function extractVariablesFromFirstServerMessage(data) {
77
79
  var nonce, salt, iteration
78
80
 
79
- String(data).split(',').forEach(function (part) {
80
- switch (part[0]) {
81
- case 'r':
82
- nonce = part.substr(2)
83
- break
84
- case 's':
85
- salt = part.substr(2)
86
- break
87
- case 'i':
88
- iteration = parseInt(part.substr(2), 10)
89
- break
90
- }
91
- })
81
+ String(data)
82
+ .split(',')
83
+ .forEach(function (part) {
84
+ switch (part[0]) {
85
+ case 'r':
86
+ nonce = part.substr(2)
87
+ break
88
+ case 's':
89
+ salt = part.substr(2)
90
+ break
91
+ case 'i':
92
+ iteration = parseInt(part.substr(2), 10)
93
+ break
94
+ }
95
+ })
92
96
 
93
97
  if (!nonce) {
94
98
  throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: nonce missing')
@@ -105,11 +109,11 @@ function extractVariablesFromFirstServerMessage (data) {
105
109
  return {
106
110
  nonce,
107
111
  salt,
108
- iteration
112
+ iteration,
109
113
  }
110
114
  }
111
115
 
112
- function xorBuffers (a, b) {
116
+ function xorBuffers(a, b) {
113
117
  if (!Buffer.isBuffer(a)) a = Buffer.from(a)
114
118
  if (!Buffer.isBuffer(b)) b = Buffer.from(b)
115
119
  var res = []
@@ -125,11 +129,11 @@ function xorBuffers (a, b) {
125
129
  return Buffer.from(res)
126
130
  }
127
131
 
128
- function createHMAC (key, msg) {
132
+ function createHMAC(key, msg) {
129
133
  return crypto.createHmac('sha256', key).update(msg).digest()
130
134
  }
131
135
 
132
- function Hi (password, saltBytes, iterations) {
136
+ function Hi(password, saltBytes, iterations) {
133
137
  var ui1 = createHMAC(password, Buffer.concat([saltBytes, Buffer.from([0, 0, 0, 1])]))
134
138
  var ui = ui1
135
139
  for (var i = 0; i < iterations - 1; i++) {
@@ -143,5 +147,5 @@ function Hi (password, saltBytes, iterations) {
143
147
  module.exports = {
144
148
  startSession,
145
149
  continueSession,
146
- finalizeSession
150
+ finalizeSession,
147
151
  }
@@ -9,7 +9,7 @@
9
9
 
10
10
  var types = require('pg-types')
11
11
 
12
- function TypeOverrides (userTypes) {
12
+ function TypeOverrides(userTypes) {
13
13
  this._types = userTypes || types
14
14
  this.text = {}
15
15
  this.binary = {}
@@ -17,9 +17,12 @@ function TypeOverrides (userTypes) {
17
17
 
18
18
  TypeOverrides.prototype.getOverrides = function (format) {
19
19
  switch (format) {
20
- case 'text': return this.text
21
- case 'binary': return this.binary
22
- default: return {}
20
+ case 'text':
21
+ return this.text
22
+ case 'binary':
23
+ return this.binary
24
+ default:
25
+ return {}
23
26
  }
24
27
  }
25
28
 
package/lib/utils.js CHANGED
@@ -11,10 +11,8 @@ const crypto = require('crypto')
11
11
 
12
12
  const defaults = require('./defaults')
13
13
 
14
- function escapeElement (elementRepresentation) {
15
- var escaped = elementRepresentation
16
- .replace(/\\/g, '\\\\')
17
- .replace(/"/g, '\\"')
14
+ function escapeElement(elementRepresentation) {
15
+ var escaped = elementRepresentation.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
18
16
 
19
17
  return '"' + escaped + '"'
20
18
  }
@@ -22,7 +20,7 @@ function escapeElement (elementRepresentation) {
22
20
  // convert a JS array to a postgres array literal
23
21
  // uses comma separator so won't work for types like box that use
24
22
  // a different array separator.
25
- function arrayString (val) {
23
+ function arrayString(val) {
26
24
  var result = '{'
27
25
  for (var i = 0; i < val.length; i++) {
28
26
  if (i > 0) {
@@ -76,7 +74,7 @@ var prepareValue = function (val, seen) {
76
74
  return val.toString()
77
75
  }
78
76
 
79
- function prepareObject (val, seen) {
77
+ function prepareObject(val, seen) {
80
78
  if (val && typeof val.toPostgres === 'function') {
81
79
  seen = seen || []
82
80
  if (seen.indexOf(val) !== -1) {
@@ -89,48 +87,66 @@ function prepareObject (val, seen) {
89
87
  return JSON.stringify(val)
90
88
  }
91
89
 
92
- function pad (number, digits) {
90
+ function pad(number, digits) {
93
91
  number = '' + number
94
- while (number.length < digits) { number = '0' + number }
92
+ while (number.length < digits) {
93
+ number = '0' + number
94
+ }
95
95
  return number
96
96
  }
97
97
 
98
- function dateToString (date) {
98
+ function dateToString(date) {
99
99
  var offset = -date.getTimezoneOffset()
100
100
 
101
101
  var year = date.getFullYear()
102
102
  var isBCYear = year < 1
103
103
  if (isBCYear) year = Math.abs(year) + 1 // negative years are 1 off their BC representation
104
104
 
105
- var ret = pad(year, 4) + '-' +
106
- pad(date.getMonth() + 1, 2) + '-' +
107
- pad(date.getDate(), 2) + 'T' +
108
- pad(date.getHours(), 2) + ':' +
109
- pad(date.getMinutes(), 2) + ':' +
110
- pad(date.getSeconds(), 2) + '.' +
105
+ var ret =
106
+ pad(year, 4) +
107
+ '-' +
108
+ pad(date.getMonth() + 1, 2) +
109
+ '-' +
110
+ pad(date.getDate(), 2) +
111
+ 'T' +
112
+ pad(date.getHours(), 2) +
113
+ ':' +
114
+ pad(date.getMinutes(), 2) +
115
+ ':' +
116
+ pad(date.getSeconds(), 2) +
117
+ '.' +
111
118
  pad(date.getMilliseconds(), 3)
112
119
 
113
120
  if (offset < 0) {
114
121
  ret += '-'
115
122
  offset *= -1
116
- } else { ret += '+' }
123
+ } else {
124
+ ret += '+'
125
+ }
117
126
 
118
127
  ret += pad(Math.floor(offset / 60), 2) + ':' + pad(offset % 60, 2)
119
128
  if (isBCYear) ret += ' BC'
120
129
  return ret
121
130
  }
122
131
 
123
- function dateToStringUTC (date) {
132
+ function dateToStringUTC(date) {
124
133
  var year = date.getUTCFullYear()
125
134
  var isBCYear = year < 1
126
135
  if (isBCYear) year = Math.abs(year) + 1 // negative years are 1 off their BC representation
127
136
 
128
- var ret = pad(year, 4) + '-' +
129
- pad(date.getUTCMonth() + 1, 2) + '-' +
130
- pad(date.getUTCDate(), 2) + 'T' +
131
- pad(date.getUTCHours(), 2) + ':' +
132
- pad(date.getUTCMinutes(), 2) + ':' +
133
- pad(date.getUTCSeconds(), 2) + '.' +
137
+ var ret =
138
+ pad(year, 4) +
139
+ '-' +
140
+ pad(date.getUTCMonth() + 1, 2) +
141
+ '-' +
142
+ pad(date.getUTCDate(), 2) +
143
+ 'T' +
144
+ pad(date.getUTCHours(), 2) +
145
+ ':' +
146
+ pad(date.getUTCMinutes(), 2) +
147
+ ':' +
148
+ pad(date.getUTCSeconds(), 2) +
149
+ '.' +
134
150
  pad(date.getUTCMilliseconds(), 3)
135
151
 
136
152
  ret += '+00:00'
@@ -138,9 +154,9 @@ function dateToStringUTC (date) {
138
154
  return ret
139
155
  }
140
156
 
141
- function normalizeQueryConfig (config, values, callback) {
157
+ function normalizeQueryConfig(config, values, callback) {
142
158
  // can take in strings or config objects
143
- config = (typeof (config) === 'string') ? { text: config } : config
159
+ config = typeof config === 'string' ? { text: config } : config
144
160
  if (values) {
145
161
  if (typeof values === 'function') {
146
162
  config.callback = values
@@ -166,12 +182,12 @@ const postgresMd5PasswordHash = function (user, password, salt) {
166
182
  }
167
183
 
168
184
  module.exports = {
169
- prepareValue: function prepareValueWrapper (value) {
185
+ prepareValue: function prepareValueWrapper(value) {
170
186
  // this ensures that extra arguments do not get passed into prepareValue
171
187
  // by accident, eg: from calling values.map(utils.prepareValue)
172
188
  return prepareValue(value)
173
189
  },
174
190
  normalizeQueryConfig,
175
191
  postgresMd5PasswordHash,
176
- md5
192
+ md5,
177
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg",
3
- "version": "8.0.2",
3
+ "version": "8.0.3",
4
4
  "description": "PostgreSQL client - pure javascript & libpq with the same API",
5
5
  "keywords": [
6
6
  "database",
@@ -22,8 +22,8 @@
22
22
  "buffer-writer": "2.0.0",
23
23
  "packet-reader": "1.0.0",
24
24
  "pg-connection-string": "0.1.3",
25
- "pg-pool": "^3.1.0",
26
- "pg-protocol": "^1.2.1",
25
+ "pg-pool": "^3.1.1",
26
+ "pg-protocol": "^1.2.2",
27
27
  "pg-types": "^2.1.0",
28
28
  "pgpass": "1.x",
29
29
  "semver": "4.3.2"
@@ -32,18 +32,11 @@
32
32
  "async": "0.9.0",
33
33
  "bluebird": "3.5.2",
34
34
  "co": "4.6.0",
35
- "eslint": "^6.0.1",
36
- "eslint-config-standard": "^13.0.1",
37
- "eslint-plugin-import": "^2.18.1",
38
- "eslint-plugin-node": "^9.1.0",
39
- "eslint-plugin-promise": "^4.2.1",
40
- "eslint-plugin-standard": "^4.0.0",
41
35
  "pg-copy-streams": "0.3.0"
42
36
  },
43
37
  "minNativeVersion": "2.0.0",
44
38
  "scripts": {
45
- "test": "make test-all",
46
- "lint": "make lint"
39
+ "test": "make test-all"
47
40
  },
48
41
  "files": [
49
42
  "lib",
@@ -53,5 +46,5 @@
53
46
  "engines": {
54
47
  "node": ">= 8.0.0"
55
48
  },
56
- "gitHead": "da03b3f9050c85a7722413a03c199cc3bdbcf5bf"
49
+ "gitHead": "35328807e3612cb267bee86dccb2551ad186624a"
57
50
  }