Skip to content

Commit 4ba9912

Browse files
committed
Merge branch 'esm-compatibility' into mitar
2 parents 279a4ab + 6720773 commit 4ba9912

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/index.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,30 @@ const poolFactory = (Client) => {
1414
}
1515
}
1616

17-
module.exports = {
18-
defaults: defaults,
19-
_pools: [],
20-
Connection: Connection,
21-
types: require('pg-types'),
22-
DatabaseError: DatabaseError,
17+
var PG = function (exports, clientConstructor) {
18+
exports.defaults = defaults
19+
exports.Client = clientConstructor
20+
exports.Query = exports.Client.Query
21+
exports.Pool = poolFactory(exports.Client)
22+
exports._pools = []
23+
exports.Connection = Connection
24+
exports.types = require('pg-types')
25+
exports.DatabaseError = DatabaseError
2326
}
2427

2528
if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
26-
var nativeClient = require('./native')
27-
module.exports.Client = nativeClient
28-
module.exports.Query = nativeClient.Query
29-
module.exports.Pool = poolFactory(nativeClient)
29+
PG(module.exports, require('./native'))
3030
} else {
31-
module.exports.Client = Client
32-
module.exports.Query = Client.Query
33-
module.exports.Pool = poolFactory(Client)
31+
PG(module.exports, Client)
3432

3533
// lazy require native module...the native module may not have installed
3634
Object.defineProperty(module.exports, 'native', {
3735
configurable: true,
3836
enumerable: false,
3937
get() {
40-
var native = null
38+
var native = {}
4139
try {
42-
native = new PG(require('./native'))
40+
PG(native, require('./native'))
4341
} catch (err) {
4442
if (err.code !== 'MODULE_NOT_FOUND') {
4543
throw err

0 commit comments

Comments
 (0)