diff --git a/common.js b/common.js deleted file mode 100644 index 66cd0b2bbb..0000000000 --- a/common.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const Connection = require('./lib/connection.js'); -const ConnectionConfig = require('./lib/connection_config.js'); -const Pool = require('./lib/pool'); -const PoolConfig = require('./lib/pool_config'); -const PoolCluster = require('./lib/pool_cluster'); - -exports.Connection = Connection; -exports.createConnection = function(opts) { - return new Connection({ config: new ConnectionConfig(opts) }); -}; -exports.createPool = function(config) { - return new Pool({ config: new PoolConfig(config) }); -}; -exports.createPoolCluster = function(config) { - const PoolCluster = require('./lib/pool_cluster.js'); - return new PoolCluster(config); -}; diff --git a/index.js b/index.js index 928eec4d42..0d7179c2a7 100644 --- a/index.js +++ b/index.js @@ -3,23 +3,25 @@ const SqlString = require('sqlstring'); const ConnectionConfig = require('./lib/connection_config.js'); -const parserCache = require('./lib/parsers/parser_cache'); +const parserCache = require('./lib/parsers/parser_cache.js'); -const common = require('./common'); -exports.createConnection = common.createConnection +const Connection = require('./lib/connection.js'); +exports.createConnection = require('./lib/create_connection.js'); exports.connect = exports.createConnection; -exports.Connection = common.Connection; +exports.Connection = Connection exports.ConnectionConfig = ConnectionConfig; const Pool = require('./lib/pool.js'); const PoolCluster = require('./lib/pool_cluster.js'); +const createPool = require('./lib/create_pool.js'); +const createPoolCluster = require('./lib/create_pool_cluster.js'); -exports.createPool = common.createPool +exports.createPool = createPool -exports.createPoolCluster = common.createPoolCluster; +exports.createPoolCluster = createPoolCluster; -exports.createQuery = common.Connection.createQuery; +exports.createQuery = Connection.createQuery; exports.Pool = Pool; @@ -34,7 +36,7 @@ exports.createServer = function(handler) { return s; }; -exports.PoolConnection = require('./lib/pool_connection'); +exports.PoolConnection = require('./lib/pool_connection.js'); exports.authPlugins = require('./lib/auth_plugins'); exports.escape = SqlString.escape; exports.escapeId = SqlString.escapeId; diff --git a/lib/create_connection.js b/lib/create_connection.js new file mode 100644 index 0000000000..d39618f78f --- /dev/null +++ b/lib/create_connection.js @@ -0,0 +1,10 @@ +'use strict'; + +const Connection = require('./connection.js'); +const ConnectionConfig = require('./connection_config.js'); + +function createConnection(opts) { + return new Connection({ config: new ConnectionConfig(opts) }); +} + +module.exports = createConnection; diff --git a/lib/create_pool.js b/lib/create_pool.js new file mode 100644 index 0000000000..7f782aff9a --- /dev/null +++ b/lib/create_pool.js @@ -0,0 +1,10 @@ +'use strict'; + +const Pool = require('./pool.js'); +const PoolConfig = require('./pool_config.js'); + +function createPool(config) { + return new Pool({ config: new PoolConfig(config) }); +} + +module.exports = createPool diff --git a/lib/create_pool_cluster.js b/lib/create_pool_cluster.js new file mode 100644 index 0000000000..4ded78b783 --- /dev/null +++ b/lib/create_pool_cluster.js @@ -0,0 +1,9 @@ +'use strict'; + +const PoolCluster = require('./pool_cluster.js'); + +function createPoolCluster(config) { + return new PoolCluster(config); +} + +module.exports = createPoolCluster; diff --git a/package.json b/package.json index 07ab95d93f..b05dd0b628 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "typings/mysql", "index.js", "index.d.ts", - "common.js", "promise.js", "promise.d.ts" ], diff --git a/promise.js b/promise.js index 04eaff6433..32cd8dc4c2 100644 --- a/promise.js +++ b/promise.js @@ -1,12 +1,15 @@ 'use strict'; const SqlString = require('sqlstring'); -const common = require('./common.js'); const EventEmitter = require('events').EventEmitter; const parserCache = require('./lib/parsers/parser_cache.js'); const PoolConnection = require('./lib/pool_connection.js'); const Pool = require('./lib/pool.js'); const PoolCluster = require('./lib/pool_cluster.js'); +const createConnection = require('./lib/create_connection.js'); +const Connection = require('./lib/connection.js'); +const createPool = require('./lib/create_pool.js'); +const createPoolCluster = require('./lib/create_pool_cluster.js'); function makeDoneCb(resolve, reject, localErr) { return function (err, rows, fields) { @@ -252,8 +255,8 @@ class PromiseConnection extends EventEmitter { } } -function createConnection(opts) { - const coreConnection = common.createConnection(opts); +function createConnectionPromise(opts) { + const coreConnection = createConnection(opts); const createConnectionErr = new Error(); const thePromise = opts.Promise || Promise; if (!thePromise) { @@ -290,12 +293,12 @@ function createConnection(opts) { const func = functionsToWrap[i]; if ( - typeof common.Connection.prototype[func] === 'function' && + typeof Connection.prototype[func] === 'function' && PromiseConnection.prototype[func] === undefined ) { PromiseConnection.prototype[func] = (function factory(funcName) { return function () { - return common.Connection.prototype[funcName].apply( + return Connection.prototype[funcName].apply( this.connection, arguments ); @@ -411,8 +414,8 @@ class PromisePool extends EventEmitter { } } -function createPool(opts) { - const corePool = common.createPool(opts); +function createPromisePool(opts) { + const corePool = createPool(opts); const thePromise = opts.Promise || Promise; if (!thePromise) { throw new Error( @@ -545,8 +548,8 @@ class PromisePoolCluster extends EventEmitter { 'add' ]); -function createPoolCluster(opts) { - const corePoolCluster = common.createPoolCluster(opts); +function createPromisePoolCluster(opts) { + const corePoolCluster = createPoolCluster(opts); const thePromise = (opts && opts.Promise) || Promise; if (!thePromise) { throw new Error( @@ -558,9 +561,9 @@ function createPoolCluster(opts) { return new PromisePoolCluster(corePoolCluster, thePromise); } -exports.createConnection = createConnection; -exports.createPool = createPool; -exports.createPoolCluster = createPoolCluster; +exports.createConnection = createConnectionPromise; +exports.createPool = createPromisePool; +exports.createPoolCluster = createPromisePoolCluster; exports.escape = SqlString.escape; exports.escapeId = SqlString.escapeId; exports.format = SqlString.format;