@@ -14,32 +14,30 @@ const poolFactory = (Client) => {
14
14
}
15
15
}
16
16
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
23
26
}
24
27
25
28
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' ) )
30
30
} else {
31
- module . exports . Client = Client
32
- module . exports . Query = Client . Query
33
- module . exports . Pool = poolFactory ( Client )
31
+ PG ( module . exports , Client )
34
32
35
33
// lazy require native module...the native module may not have installed
36
34
Object . defineProperty ( module . exports , 'native' , {
37
35
configurable : true ,
38
36
enumerable : false ,
39
37
get ( ) {
40
- var native = null
38
+ var native = { }
41
39
try {
42
- native = new PG ( require ( './native' ) )
40
+ PG ( native , require ( './native' ) )
43
41
} catch ( err ) {
44
42
if ( err . code !== 'MODULE_NOT_FOUND' ) {
45
43
throw err
0 commit comments