From e493ad003209c8aab0d78521d61b8d846677699c Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:14:38 +0100 Subject: [PATCH 1/9] chore: use ES6 classes This improves readability and may allow V8 to optimize better. --- packages/pg-native/lib/copy-stream.js | 181 +++++++++++++------------- 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/packages/pg-native/lib/copy-stream.js b/packages/pg-native/lib/copy-stream.js index 94ae4f7e5..6a98bf54e 100644 --- a/packages/pg-native/lib/copy-stream.js +++ b/packages/pg-native/lib/copy-stream.js @@ -2,114 +2,115 @@ const Duplex = require('stream').Duplex const Writable = require('stream').Writable const util = require('util') -const CopyStream = (module.exports = function (pq, options) { - Duplex.call(this, options) - this.pq = pq - this._reading = false -}) -util.inherits(CopyStream, Duplex) - -// writer methods -CopyStream.prototype._write = function (chunk, encoding, cb) { - const result = this.pq.putCopyData(chunk) - - // sent successfully - if (result === 1) return cb() +class CopyStream extends Duplex { + constructor(pq, options) { + super(options); + this.pq = pq; + this._reading = false; + } - // error - if (result === -1) return cb(new Error(this.pq.errorMessage())) - // command would block. wait for writable and call again. - const self = this - this.pq.writable(function () { - self._write(chunk, encoding, cb) - }) -} + // writer methods + _write(chunk, encoding, cb) { + const result = this.pq.putCopyData(chunk) -CopyStream.prototype.end = function () { - const args = Array.prototype.slice.call(arguments, 0) - const self = this + // sent successfully + if (result === 1) return cb() - const callback = args.pop() + // error + if (result === -1) return cb(new Error(this.pq.errorMessage())) - if (args.length) { - this.write(args[0]) - } - const result = this.pq.putCopyEnd() - - // sent successfully - if (result === 1) { - // consume our results and then call 'end' on the - // "parent" writable class so we can emit 'finish' and - // all that jazz - return consumeResults(this.pq, function (err, res) { - Writable.prototype.end.call(self) - - // handle possible passing of callback to end method - if (callback) { - callback(err) - } + // command would block. wait for writable and call again. + const self = this + this.pq.writable(function () { + self._write(chunk, encoding, cb) }) } - // error - if (result === -1) { - const err = new Error(this.pq.errorMessage()) - return this.emit('error', err) - } + end() { + const args = Array.prototype.slice.call(arguments, 0) + const self = this - // command would block. wait for writable and call end again - // don't pass any buffers to end on the second call because - // we already sent them to possible this.write the first time - // we called end - return this.pq.writable(function () { - return self.end.apply(self, callback) - }) -} + const callback = args.pop() + + if (args.length) { + this.write(args[0]) + } + const result = this.pq.putCopyEnd() + + // sent successfully + if (result === 1) { + // consume our results and then call 'end' on the + // "parent" writable class so we can emit 'finish' and + // all that jazz + return consumeResults(this.pq, function (err, res) { + Writable.prototype.end.call(self) + + // handle possible passing of callback to end method + if (callback) { + callback(err) + } + }) + } + + // error + if (result === -1) { + const err = new Error(this.pq.errorMessage()) + return this.emit('error', err) + } -// reader methods -CopyStream.prototype._consumeBuffer = function (cb) { - const result = this.pq.getCopyData(true) - if (result instanceof Buffer) { - return setImmediate(function () { - cb(null, result) + // command would block. wait for writable and call end again + // don't pass any buffers to end on the second call because + // we already sent them to possible this.write the first time + // we called end + return this.pq.writable(function () { + return self.end.apply(self, callback) }) } - if (result === -1) { - // end of stream - return cb(null, null) + + // reader methods + _consumeBuffer(cb) { + const result = this.pq.getCopyData(true) + if (result instanceof Buffer) { + return setImmediate(function () { + cb(null, result) + }) + } + if (result === -1) { + // end of stream + return cb(null, null) + } + if (result === 0) { + const self = this + this.pq.once('readable', function () { + self.pq.stopReader() + self.pq.consumeInput() + self._consumeBuffer(cb) + }) + return this.pq.startReader() + } + cb(new Error('Unrecognized read status: ' + result)) } - if (result === 0) { + + _read(size) { + if (this._reading) return + this._reading = true + // console.log('read begin'); const self = this - this.pq.once('readable', function () { - self.pq.stopReader() - self.pq.consumeInput() - self._consumeBuffer(cb) + this._consumeBuffer(function (err, buffer) { + self._reading = false + if (err) { + return self.emit('error', err) + } + if (buffer === false) { + // nothing to read for now, return + return + } + self.push(buffer) }) - return this.pq.startReader() } - cb(new Error('Unrecognized read status: ' + result)) } - -CopyStream.prototype._read = function (size) { - if (this._reading) return - this._reading = true - // console.log('read begin'); - const self = this - this._consumeBuffer(function (err, buffer) { - self._reading = false - if (err) { - return self.emit('error', err) - } - if (buffer === false) { - // nothing to read for now, return - return - } - self.push(buffer) - }) -} - const consumeResults = function (pq, cb) { const cleanup = function () { pq.removeListener('readable', onReadable) From 32371ebf8ec7d28d1899f4a007e054f322677903 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:16:28 +0100 Subject: [PATCH 2/9] chore: remove util --- packages/pg-native/lib/copy-stream.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/pg-native/lib/copy-stream.js b/packages/pg-native/lib/copy-stream.js index 6a98bf54e..c81fafb53 100644 --- a/packages/pg-native/lib/copy-stream.js +++ b/packages/pg-native/lib/copy-stream.js @@ -1,7 +1,4 @@ -const Duplex = require('stream').Duplex -const Writable = require('stream').Writable -const util = require('util') - +const { Duplex, Writable } = require('stream') class CopyStream extends Duplex { constructor(pq, options) { From 2a4d108e549b99a07a9d1a2ad65ce53558dcff68 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:17:25 +0100 Subject: [PATCH 3/9] fix: export --- packages/pg-native/lib/copy-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg-native/lib/copy-stream.js b/packages/pg-native/lib/copy-stream.js index c81fafb53..29f248132 100644 --- a/packages/pg-native/lib/copy-stream.js +++ b/packages/pg-native/lib/copy-stream.js @@ -1,6 +1,6 @@ const { Duplex, Writable } = require('stream') -class CopyStream extends Duplex { +module.exports = class CopyStream extends Duplex { constructor(pq, options) { super(options); this.pq = pq; From 4b366e30ff17b4c8b99696554155ef0fa9e4c0ee Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:20:24 +0100 Subject: [PATCH 4/9] fix: lint --- packages/pg-native/lib/copy-stream.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/pg-native/lib/copy-stream.js b/packages/pg-native/lib/copy-stream.js index 29f248132..0a4afc68c 100644 --- a/packages/pg-native/lib/copy-stream.js +++ b/packages/pg-native/lib/copy-stream.js @@ -2,12 +2,11 @@ const { Duplex, Writable } = require('stream') module.exports = class CopyStream extends Duplex { constructor(pq, options) { - super(options); - this.pq = pq; - this._reading = false; + super(options) + this.pq = pq + this._reading = false } - // writer methods _write(chunk, encoding, cb) { const result = this.pq.putCopyData(chunk) From 8b746b6b57fff3be901a1b7741ba2c13317d87f2 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:38:38 +0100 Subject: [PATCH 5/9] chore: refactor Client to use ES6 class --- packages/pg-native/index.js | 518 ++++++++++++++++++------------------ 1 file changed, 258 insertions(+), 260 deletions(-) diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index 8c83406bb..d6378ead8 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -6,326 +6,324 @@ const types = require('pg-types') const buildResult = require('./lib/build-result') const CopyStream = require('./lib/copy-stream') -const Client = (module.exports = function (config) { - if (!(this instanceof Client)) { - return new Client(config) - } - - config = config || {} - - EventEmitter.call(this) - this.pq = new Libpq() - this._reading = false - this._read = this._read.bind(this) - - // allow custom type conversion to be passed in - this._types = config.types || types +module.exports = class Client extends EventEmitter { + constructor (config) { + if (!(this instanceof Client)) { + return new Client(config) + } - // allow config to specify returning results - // as an array of values instead of a hash - this.arrayMode = config.arrayMode || false - this._resultCount = 0 - this._rows = undefined - this._results = undefined + config = config || {} - // lazy start the reader if notifications are listened for - // this way if you only run sync queries you wont block - // the event loop artificially - this.on('newListener', (event) => { - if (event !== 'notification') return - this._startReading() - }) + this.pq = new Libpq() + this._reading = false + this._read = this._read.bind(this) - this.on('result', this._onResult.bind(this)) - this.on('readyForQuery', this._onReadyForQuery.bind(this)) -}) + // allow custom type conversion to be passed in + this._types = config.types || types -util.inherits(Client, EventEmitter) + // allow config to specify returning results + // as an array of values instead of a hash + this.arrayMode = config.arrayMode || false + this._resultCount = 0 + this._rows = undefined + this._results = undefined -Client.prototype.connect = function (params, cb) { - this.pq.connect(params, cb) -} + // lazy start the reader if notifications are listened for + // this way if you only run sync queries you wont block + // the event loop artificially + this.on('newListener', (event) => { + if (event !== 'notification') return + this._startReading() + }) -Client.prototype.connectSync = function (params) { - this.pq.connectSync(params) -} + this.on('result', this._onResult.bind(this)) + this.on('readyForQuery', this._onReadyForQuery.bind(this)) + } -Client.prototype.query = function (text, values, cb) { - let queryFn + connect(params, cb) { + this.pq.connect(params, cb) + } - if (typeof values === 'function') { - cb = values + connectSync(params) { + this.pq.connectSync(params) } - if (Array.isArray(values)) { - queryFn = () => { - return this.pq.sendQueryParams(text, values) + query(text, values, cb) { + let queryFn + + if (typeof values === 'function') { + cb = values } - } else { - queryFn = () => { - return this.pq.sendQuery(text) + + if (Array.isArray(values)) { + queryFn = () => { + return this.pq.sendQueryParams(text, values) + } + } else { + queryFn = () => { + return this.pq.sendQuery(text) + } } + + this._dispatchQuery(this.pq, queryFn, (err) => { + if (err) return cb(err) + this._awaitResult(cb) + }) } - this._dispatchQuery(this.pq, queryFn, (err) => { - if (err) return cb(err) - this._awaitResult(cb) - }) -} + prepare(statementName, text, nParams, cb) { + const self = this + const fn = function () { + return self.pq.sendPrepare(statementName, text, nParams) + } -Client.prototype.prepare = function (statementName, text, nParams, cb) { - const self = this - const fn = function () { - return self.pq.sendPrepare(statementName, text, nParams) + self._dispatchQuery(self.pq, fn, function (err) { + if (err) return cb(err) + self._awaitResult(cb) + }) } - self._dispatchQuery(self.pq, fn, function (err) { - if (err) return cb(err) - self._awaitResult(cb) - }) -} + execute(statementName, parameters, cb) { + const self = this -Client.prototype.execute = function (statementName, parameters, cb) { - const self = this + const fn = function () { + return self.pq.sendQueryPrepared(statementName, parameters) + } - const fn = function () { - return self.pq.sendQueryPrepared(statementName, parameters) + self._dispatchQuery(self.pq, fn, function (err, rows) { + if (err) return cb(err) + self._awaitResult(cb) + }) } - self._dispatchQuery(self.pq, fn, function (err, rows) { - if (err) return cb(err) - self._awaitResult(cb) - }) -} - -Client.prototype.getCopyStream = function () { - this.pq.setNonBlocking(true) - this._stopReading() - return new CopyStream(this.pq) -} - -// cancel a currently executing query -Client.prototype.cancel = function (cb) { - assert(cb, 'Callback is required') - // result is either true or a string containing an error - const result = this.pq.cancel() - return setImmediate(function () { - cb(result === true ? undefined : new Error(result)) - }) -} + getCopyStream() { + this.pq.setNonBlocking(true) + this._stopReading() + return new CopyStream(this.pq) + } -Client.prototype.querySync = function (text, values) { - if (values) { - this.pq.execParams(text, values) - } else { - this.pq.exec(text) + // cancel a currently executing query + cancel(cb) { + assert(cb, 'Callback is required') + // result is either true or a string containing an error + const result = this.pq.cancel() + return setImmediate(function () { + cb(result === true ? undefined : new Error(result)) + }) } - throwIfError(this.pq) - const result = buildResult(this.pq, this._types, this.arrayMode) - return result.rows -} + querySync(text, values) { + if (values) { + this.pq.execParams(text, values) + } else { + this.pq.exec(text) + } -Client.prototype.prepareSync = function (statementName, text, nParams) { - this.pq.prepare(statementName, text, nParams) - throwIfError(this.pq) -} + throwIfError(this.pq) + const result = buildResult(this.pq, this._types, this.arrayMode) + return result.rows + } -Client.prototype.executeSync = function (statementName, parameters) { - this.pq.execPrepared(statementName, parameters) - throwIfError(this.pq) - return buildResult(this.pq, this._types, this.arrayMode).rows -} + prepareSync(statementName, text, nParams) { + this.pq.prepare(statementName, text, nParams) + throwIfError(this.pq) + } -Client.prototype.escapeLiteral = function (value) { - return this.pq.escapeLiteral(value) -} + executeSync(statementName, parameters) { + this.pq.execPrepared(statementName, parameters) + throwIfError(this.pq) + return buildResult(this.pq, this._types, this.arrayMode).rows + } -Client.prototype.escapeIdentifier = function (value) { - return this.pq.escapeIdentifier(value) -} + escapeLiteral(value) { + return this.pq.escapeLiteral(value) + } -// export the version number so we can check it in node-postgres -module.exports.version = require('./package.json').version + escapeIdentifier(value) { + return this.pq.escapeIdentifier(value) + } -Client.prototype.end = function (cb) { - this._stopReading() - this.pq.finish() - if (cb) setImmediate(cb) -} + end(cb) { + this._stopReading() + this.pq.finish() + if (cb) setImmediate(cb) + } -Client.prototype._readError = function (message) { - const err = new Error(message || this.pq.errorMessage()) - this.emit('error', err) -} + _readError(message) { + const err = new Error(message || this.pq.errorMessage()) + this.emit('error', err) + } -Client.prototype._stopReading = function () { - if (!this._reading) return - this._reading = false - this.pq.stopReader() - this.pq.removeListener('readable', this._read) -} + _stopReading() { + if (!this._reading) return + this._reading = false + this.pq.stopReader() + this.pq.removeListener('readable', this._read) + } -Client.prototype._consumeQueryResults = function (pq) { - return buildResult(pq, this._types, this.arrayMode) -} + _consumeQueryResults(pq) { + return buildResult(pq, this._types, this.arrayMode) + } -Client.prototype._emitResult = function (pq) { - const status = pq.resultStatus() - switch (status) { - case 'PGRES_FATAL_ERROR': - this._queryError = new Error(this.pq.resultErrorMessage()) - break - - case 'PGRES_TUPLES_OK': - case 'PGRES_COMMAND_OK': - case 'PGRES_EMPTY_QUERY': - { - const result = this._consumeQueryResults(this.pq) - this.emit('result', result) + _emitResult(pq) { + const status = pq.resultStatus() + switch (status) { + case 'PGRES_FATAL_ERROR': + this._queryError = new Error(this.pq.resultErrorMessage()) + break + + case 'PGRES_TUPLES_OK': + case 'PGRES_COMMAND_OK': + case 'PGRES_EMPTY_QUERY': + { + const result = this._consumeQueryResults(this.pq) + this.emit('result', result) + } + break + + case 'PGRES_COPY_OUT': + case 'PGRES_COPY_BOTH': { + break } - break - case 'PGRES_COPY_OUT': - case 'PGRES_COPY_BOTH': { - break + default: + this._readError('unrecognized command status: ' + status) + break } - - default: - this._readError('unrecognized command status: ' + status) - break + return status } - return status -} -// called when libpq is readable -Client.prototype._read = function () { - const pq = this.pq - // read waiting data from the socket - // e.g. clear the pending 'select' - if (!pq.consumeInput()) { - // if consumeInput returns false - // than a read error has been encountered - return this._readError() - } + // called when libpq is readable + _read() { + const pq = this.pq + // read waiting data from the socket + // e.g. clear the pending 'select' + if (!pq.consumeInput()) { + // if consumeInput returns false + // than a read error has been encountered + return this._readError() + } - // check if there is still outstanding data - // if so, wait for it all to come in - if (pq.isBusy()) { - return - } + // check if there is still outstanding data + // if so, wait for it all to come in + if (pq.isBusy()) { + return + } - // load our result object + // load our result object - while (pq.getResult()) { - const resultStatus = this._emitResult(this.pq) + while (pq.getResult()) { + const resultStatus = this._emitResult(this.pq) - // if the command initiated copy mode we need to break out of the read loop - // so a substream can begin to read copy data - if (resultStatus === 'PGRES_COPY_BOTH' || resultStatus === 'PGRES_COPY_OUT') { - break - } + // if the command initiated copy mode we need to break out of the read loop + // so a substream can begin to read copy data + if (resultStatus === 'PGRES_COPY_BOTH' || resultStatus === 'PGRES_COPY_OUT') { + break + } - // if reading multiple results, sometimes the following results might cause - // a blocking read. in this scenario yield back off the reader until libpq is readable - if (pq.isBusy()) { - return + // if reading multiple results, sometimes the following results might cause + // a blocking read. in this scenario yield back off the reader until libpq is readable + if (pq.isBusy()) { + return + } } - } - this.emit('readyForQuery') + this.emit('readyForQuery') - let notice = this.pq.notifies() - while (notice) { - this.emit('notification', notice) - notice = this.pq.notifies() + let notice = this.pq.notifies() + while (notice) { + this.emit('notification', notice) + notice = this.pq.notifies() + } } -} - -// ensures the client is reading and -// everything is set up for async io -Client.prototype._startReading = function () { - if (this._reading) return - this._reading = true - this.pq.on('readable', this._read) - this.pq.startReader() -} -const throwIfError = function (pq) { - const err = pq.resultErrorMessage() || pq.errorMessage() - if (err) { - throw new Error(err) + // ensures the client is reading and + // everything is set up for async io + _startReading() { + if (this._reading) return + this._reading = true + this.pq.on('readable', this._read) + this.pq.startReader() } -} -Client.prototype._awaitResult = function (cb) { - this._queryCallback = cb - return this._startReading() -} + _awaitResult(cb) { + this._queryCallback = cb + return this._startReading() + } -// wait for the writable socket to drain -Client.prototype._waitForDrain = function (pq, cb) { - const res = pq.flush() - // res of 0 is success - if (res === 0) return cb() - - // res of -1 is failure - if (res === -1) return cb(pq.errorMessage()) - - // otherwise outgoing message didn't flush to socket - // wait for it to flush and try again - const self = this - // you cannot read & write on a socket at the same time - return pq.writable(function () { - self._waitForDrain(pq, cb) - }) -} + // wait for the writable socket to drain + _waitForDrain(pq, cb) { + const res = pq.flush() + // res of 0 is success + if (res === 0) return cb() + + // res of -1 is failure + if (res === -1) return cb(pq.errorMessage()) + + // otherwise outgoing message didn't flush to socket + // wait for it to flush and try again + const self = this + // you cannot read & write on a socket at the same time + return pq.writable(function () { + self._waitForDrain(pq, cb) + }) + } -// send an async query to libpq and wait for it to -// finish writing query text to the socket -Client.prototype._dispatchQuery = function (pq, fn, cb) { - this._stopReading() - const success = pq.setNonBlocking(true) - if (!success) return cb(new Error('Unable to set non-blocking to true')) - const sent = fn() - if (!sent) return cb(new Error(pq.errorMessage() || 'Something went wrong dispatching the query')) - this._waitForDrain(pq, cb) -} + // send an async query to libpq and wait for it to + // finish writing query text to the socket + _dispatchQuery(pq, fn, cb) { + this._stopReading() + const success = pq.setNonBlocking(true) + if (!success) return cb(new Error('Unable to set non-blocking to true')) + const sent = fn() + if (!sent) return cb(new Error(pq.errorMessage() || 'Something went wrong dispatching the query')) + this._waitForDrain(pq, cb) + } -Client.prototype._onResult = function (result) { - if (this._resultCount === 0) { - this._results = result - this._rows = result.rows - } else if (this._resultCount === 1) { - this._results = [this._results, result] - this._rows = [this._rows, result.rows] - } else { - this._results.push(result) - this._rows.push(result.rows) + _onResult(result) { + if (this._resultCount === 0) { + this._results = result + this._rows = result.rows + } else if (this._resultCount === 1) { + this._results = [this._results, result] + this._rows = [this._rows, result.rows] + } else { + this._results.push(result) + this._rows.push(result.rows) + } + this._resultCount++ } - this._resultCount++ -} -Client.prototype._onReadyForQuery = function () { - // remove instance callback - const cb = this._queryCallback - this._queryCallback = undefined + _onReadyForQuery() { + // remove instance callback + const cb = this._queryCallback + this._queryCallback = undefined - // remove instance query error - const err = this._queryError - this._queryError = undefined + // remove instance query error + const err = this._queryError + this._queryError = undefined - // remove instance rows - const rows = this._rows - this._rows = undefined + // remove instance rows + const rows = this._rows + this._rows = undefined - // remove instance results - const results = this._results - this._results = undefined + // remove instance results + const results = this._results + this._results = undefined - this._resultCount = 0 + this._resultCount = 0 - if (cb) { - cb(err, rows || [], results) + if (cb) { + cb(err, rows || [], results) + } + } +} +const throwIfError = function (pq) { + const err = pq.resultErrorMessage() || pq.errorMessage() + if (err) { + throw new Error(err) } } + +// export the version number so we can check it in node-postgres +module.exports.version = require('./package.json').version From d55d21158f01ee3a9f3bab542e760b9bb09c8d99 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:41:47 +0100 Subject: [PATCH 6/9] fix: lint --- packages/pg-native/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index d6378ead8..c95fc698d 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -1,13 +1,13 @@ const Libpq = require('libpq') const EventEmitter = require('events').EventEmitter -const util = require('util') const assert = require('assert') const types = require('pg-types') const buildResult = require('./lib/build-result') const CopyStream = require('./lib/copy-stream') module.exports = class Client extends EventEmitter { - constructor (config) { + constructor(config) { + super() if (!(this instanceof Client)) { return new Client(config) } From 163572eb5f274ca1a71c89efc95944b0c4406696 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:54:16 +0100 Subject: [PATCH 7/9] fix: old js --- packages/pg-native/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index c95fc698d..428f500da 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -5,7 +5,7 @@ const types = require('pg-types') const buildResult = require('./lib/build-result') const CopyStream = require('./lib/copy-stream') -module.exports = class Client extends EventEmitter { +class ClientClass extends EventEmitter { constructor(config) { super() if (!(this instanceof Client)) { @@ -327,3 +327,7 @@ const throwIfError = function (pq) { // export the version number so we can check it in node-postgres module.exports.version = require('./package.json').version + +module.exports = function Client(config) { + return new ClientClass(config); +} From 93e659a5f16b3081dcced2499780f741dc97f99b Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 15 Dec 2025 17:56:06 +0100 Subject: [PATCH 8/9] fix: lint --- packages/pg-native/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index 428f500da..6b71cea4a 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -8,9 +8,6 @@ const CopyStream = require('./lib/copy-stream') class ClientClass extends EventEmitter { constructor(config) { super() - if (!(this instanceof Client)) { - return new Client(config) - } config = config || {} @@ -329,5 +326,5 @@ const throwIfError = function (pq) { module.exports.version = require('./package.json').version module.exports = function Client(config) { - return new ClientClass(config); + return new ClientClass(config) } From eafb2cb4766b752c45e106058cad3aa3eb22a0d6 Mon Sep 17 00:00:00 2001 From: francesco Date: Tue, 16 Dec 2025 09:00:31 +0100 Subject: [PATCH 9/9] fix: legacy --- packages/pg-native/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/pg-native/index.js b/packages/pg-native/index.js index 6b71cea4a..0c9a257be 100644 --- a/packages/pg-native/index.js +++ b/packages/pg-native/index.js @@ -5,7 +5,7 @@ const types = require('pg-types') const buildResult = require('./lib/build-result') const CopyStream = require('./lib/copy-stream') -class ClientClass extends EventEmitter { +class Client extends EventEmitter { constructor(config) { super() @@ -322,9 +322,11 @@ const throwIfError = function (pq) { } } +function createClient(config) { + return new Client(config) +} + +module.exports = createClient +module.exports.Client = Client // export the version number so we can check it in node-postgres module.exports.version = require('./package.json').version - -module.exports = function Client(config) { - return new ClientClass(config) -}