diff --git a/lib/factory.js b/lib/factory.js new file mode 100644 index 000000000..c2c825f42 --- /dev/null +++ b/lib/factory.js @@ -0,0 +1,36 @@ +'use strict' +/** + * Copyright (c) 2010-2017 Brian Carlson (brian.m.carlson@gmail.com) + * All rights reserved. + * + * This source code is licensed under the MIT license found in the + * README.md file in the root directory of this source tree. + */ + +const util = require('util') +const defaults = require('./defaults') +const Connection = require('./connection') +const Pool = require('@micburks/pg-pool') + +const poolFactory = (Client) => { + var BoundPool = function (options) { + var config = Object.assign({ Client: Client }, options) + return new Pool(config) + } + + util.inherits(BoundPool, Pool) + + return BoundPool +} + +const 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') +} + +module.exports = PG; diff --git a/lib/index.js b/lib/index.js index 8e000a378..491f370b2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,53 +7,7 @@ * README.md file in the root directory of this source tree. */ -var util = require('util') -var Client = require('./client') -var defaults = require('./defaults') -var Connection = require('./connection') -var Pool = require('pg-pool') +const Client = require('./client'); +const PG = require('./factory.js'); -const poolFactory = (Client) => { - var BoundPool = function (options) { - var config = Object.assign({ Client: Client }, options) - return new Pool(config) - } - - util.inherits(BoundPool, Pool) - - return BoundPool -} - -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') -} - -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 - module.exports.__defineGetter__('native', function () { - delete module.exports.native - var native = null - try { - native = new PG(require('./native')) - } catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') { - throw err - } - /* eslint-disable no-console */ - console.error(err.message) - /* eslint-enable no-console */ - } - module.exports.native = native - return native - }) -} +module.exports = new PG(Client) diff --git a/lib/native/index.js b/lib/native/index.js index eead422a3..9bfd48bf9 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -1,2 +1,5 @@ 'use strict' -module.exports = require('./client') + +const PG = require('../factory.js'); + +module.exports = new PG(require('./client')); diff --git a/package.json b/package.json index c7b3ce039..6c2238252 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "pg", - "version": "7.11.0", + "name": "@micburks/pg", + "version": "8.0.1", "description": "PostgreSQL client - pure javascript & libpq with the same API", "keywords": [ "database", @@ -17,12 +17,15 @@ "url": "git://github.com/brianc/node-postgres.git" }, "author": "Brian Carlson ", + "contributors": [ + "Mickey Burks " + ], "main": "./lib", "dependencies": { + "@micburks/pg-pool": "^3.0.0", "buffer-writer": "2.0.0", "packet-reader": "1.0.0", "pg-connection-string": "0.1.3", - "pg-pool": "^2.0.4", "pg-types": "~2.0.0", "pgpass": "1.x", "semver": "4.3.2"