mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
* build: add esm exports * fix: add defaults as per arethetypeswrong report * fix: add missing types * lint * Fix broken tests * Add (failing) test for esm compat * Begin moving files to proper extension and adding tests * Add tests for connection-string and fix cloudflare module type and esm compat * Add query-stream and cursor as esm exports * Update PR copilot review * Publish - pg-cloudflare@1.1.2-alpha.0 - pg-connection-string@2.7.1-alpha.0 - pg-cursor@2.13.2-alpha.0 - pg-esm-test@1.0.1-alpha.0 - pg-native@3.3.1-alpha.0 - pg-pool@3.8.1-alpha.0 - pg-protocol@1.8.1-alpha.0 - pg-query-stream@4.8.2-alpha.0 - pg@8.14.2-alpha.0 * More cf compat work * Publish - pg-cloudflare@1.1.2-alpha.1 - pg-cursor@2.13.2-alpha.1 - pg-esm-test@1.0.1-alpha.1 - pg-pool@3.8.1-alpha.1 - pg-query-stream@4.8.2-alpha.1 - pg@8.14.2-alpha.1 * Add more cf compat and update tests * Make tests pass - update exports for esm * Use env vars for test connection in cf tests * Fix lint * Fit vitest into existing legacy framework * Skip worker tests on node below 18 * Revert doc changes for now * Remove legacy worker test in favor of vitest --------- Co-authored-by: Luca Ban <mesqueeb@users.noreply.github.com>
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
var Client = require('./client')
|
|
var defaults = require('./defaults')
|
|
var Connection = require('./connection')
|
|
var Result = require('./result')
|
|
var utils = require('./utils')
|
|
var Pool = require('pg-pool')
|
|
const { DatabaseError } = require('pg-protocol')
|
|
const { escapeIdentifier, escapeLiteral } = require('./utils')
|
|
|
|
const poolFactory = (Client) => {
|
|
return class BoundPool extends Pool {
|
|
constructor(options) {
|
|
super(options, Client)
|
|
}
|
|
}
|
|
}
|
|
|
|
var PG = function (clientConstructor) {
|
|
this.defaults = defaults
|
|
this.Client = clientConstructor
|
|
this.Query = this.Client.Query
|
|
this.Pool = poolFactory(this.Client)
|
|
this._pools = []
|
|
this.Connection = Connection
|
|
this.types = require('pg-types')
|
|
this.DatabaseError = DatabaseError
|
|
this.escapeIdentifier = escapeIdentifier
|
|
this.escapeLiteral = escapeLiteral
|
|
this.Result = Result
|
|
this.utils = utils
|
|
}
|
|
|
|
if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
|
|
module.exports = new PG(require('./native'))
|
|
} else {
|
|
module.exports = new PG(Client)
|
|
|
|
// lazy require native module...the native module may not have installed
|
|
Object.defineProperty(module.exports, 'native', {
|
|
configurable: true,
|
|
enumerable: false,
|
|
get() {
|
|
var native = null
|
|
try {
|
|
native = new PG(require('./native'))
|
|
} catch (err) {
|
|
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
throw err
|
|
}
|
|
}
|
|
|
|
// overwrite module.exports.native so that getter is never called again
|
|
Object.defineProperty(module.exports, 'native', {
|
|
value: native,
|
|
})
|
|
|
|
return native
|
|
},
|
|
})
|
|
}
|