Skip to content

Commit 7f2f3eb

Browse files
committed
Move native module to subdirectory
1 parent 8ba1d2c commit 7f2f3eb

File tree

4 files changed

+47
-51
lines changed

4 files changed

+47
-51
lines changed

lib/factory.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict'
2+
/**
3+
* Copyright (c) 2010-2017 Brian Carlson ([email protected])
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* README.md file in the root directory of this source tree.
8+
*/
9+
10+
var util = require('util')
11+
var defaults = require('./defaults')
12+
var Connection = require('./connection')
13+
var Pool = require('pg-pool')
14+
15+
const poolFactory = (Client) => {
16+
var BoundPool = function (options) {
17+
var config = Object.assign({ Client: Client }, options)
18+
return new Pool(config)
19+
}
20+
21+
util.inherits(BoundPool, Pool)
22+
23+
return BoundPool
24+
}
25+
26+
const PG = function (clientConstructor) {
27+
this.defaults = defaults
28+
this.Client = clientConstructor
29+
this.Query = this.Client.Query
30+
this.Pool = poolFactory(this.Client)
31+
this._pools = []
32+
this.Connection = Connection
33+
this.types = require('pg-types')
34+
}
35+
36+
module.exports = PG;

lib/index.js

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,7 @@
77
* README.md file in the root directory of this source tree.
88
*/
99

10-
var util = require('util')
11-
var Client = require('./client')
12-
var defaults = require('./defaults')
13-
var Connection = require('./connection')
14-
var Pool = require('pg-pool')
10+
const Client = require('./client');
11+
const PG = require('./factory.js');
1512

16-
const poolFactory = (Client) => {
17-
var BoundPool = function (options) {
18-
var config = Object.assign({ Client: Client }, options)
19-
return new Pool(config)
20-
}
21-
22-
util.inherits(BoundPool, Pool)
23-
24-
return BoundPool
25-
}
26-
27-
var PG = function (clientConstructor) {
28-
this.defaults = defaults
29-
this.Client = clientConstructor
30-
this.Query = this.Client.Query
31-
this.Pool = poolFactory(this.Client)
32-
this._pools = []
33-
this.Connection = Connection
34-
this.types = require('pg-types')
35-
}
36-
37-
if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
38-
module.exports = new PG(require('./native'))
39-
} else {
40-
module.exports = new PG(Client)
41-
42-
// lazy require native module...the native module may not have installed
43-
module.exports.__defineGetter__('native', function () {
44-
delete module.exports.native
45-
var native = null
46-
try {
47-
native = new PG(require('./native'))
48-
} catch (err) {
49-
if (err.code !== 'MODULE_NOT_FOUND') {
50-
throw err
51-
}
52-
/* eslint-disable no-console */
53-
console.error(err.message)
54-
/* eslint-enable no-console */
55-
}
56-
module.exports.native = native
57-
return native
58-
})
59-
}
13+
module.exports = new PG(Client)

lib/native/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
'use strict'
2-
module.exports = require('./client')
2+
3+
const PG = require('../factory.js');
4+
5+
module.exports = new PG(require('./client'));

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "pg",
2+
"name": "@micburks/pg",
33
"version": "7.11.0",
44
"description": "PostgreSQL client - pure javascript & libpq with the same API",
55
"keywords": [
@@ -17,6 +17,9 @@
1717
"url": "git://github.com/brianc/node-postgres.git"
1818
},
1919
"author": "Brian Carlson <[email protected]>",
20+
"contributors": [
21+
"Mickey Burks <[email protected]>"
22+
],
2023
"main": "./lib",
2124
"dependencies": {
2225
"buffer-writer": "2.0.0",

0 commit comments

Comments
 (0)