Make 'navtive' a connection option to use a driver with native bindings
This commit is contained in:
parent
7f22eee84d
commit
b54e69570f
@ -28,6 +28,12 @@ class NodeQuery {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param {object} config - connection parameters
|
* @param {object} config - connection parameters
|
||||||
|
* @param {string} config.driver - the database driver to use, such as mysql, sqlite, mssql, or pgsql
|
||||||
|
* @param {object|string} config.connection - the connection options for the database
|
||||||
|
* @param {string} config.connection.host - the ip or hostname of the database server
|
||||||
|
* @param {string} config.connection.user - the user to log in as
|
||||||
|
* @param {string} config.connection.password - the password to log in with
|
||||||
|
* @param {string} config.connection.database - the name of the database to connect to
|
||||||
* @example let nodeQuery = require('ci-node-query')({
|
* @example let nodeQuery = require('ci-node-query')({
|
||||||
* driver: 'mysql',
|
* driver: 'mysql',
|
||||||
* connection: {
|
* connection: {
|
||||||
|
28
lib/adapters/Pg/PgNative.js
Normal file
28
lib/adapters/Pg/PgNative.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Pg = require('./Pg');
|
||||||
|
const Result = require('../../Result');
|
||||||
|
const pg = require('pg').native;
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
class PgNative extends Pg {
|
||||||
|
constructor (config) {
|
||||||
|
super(config);
|
||||||
|
let instance = null;
|
||||||
|
let connectionString = Pg._formatConnectionString(config);
|
||||||
|
|
||||||
|
if (connectionString !== '') {
|
||||||
|
let conn = new pg.Client(connectionString);
|
||||||
|
conn.connect(err => {
|
||||||
|
if (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance = Promise.resolve(conn);
|
||||||
|
}
|
||||||
|
super(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = PgNative;
|
@ -1,7 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Pg = require('./Pg');
|
const Pg = require('./Pg');
|
||||||
|
const PgNative = require('./PgNative')
|
||||||
|
|
||||||
module.exports = config => {
|
module.exports = config => {
|
||||||
return new Pg(config.connection);
|
return (config.native)
|
||||||
|
? new PgNative(config.connection)
|
||||||
|
: new Pg(config.connection);
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = config => {
|
module.exports = config => {
|
||||||
const Implementation = (config.adapter && config.adapter === 'dblite')
|
const Implementation = (config.native)
|
||||||
? require('./dblite')
|
? require('./sqlite3')
|
||||||
: require('./sqlite3');
|
: require('./dblite');
|
||||||
|
|
||||||
return new Implementation(config.connection);
|
return new Implementation(config.connection);
|
||||||
};
|
};
|
||||||
|
@ -23,12 +23,14 @@
|
|||||||
"codeigniter",
|
"codeigniter",
|
||||||
"mariadb",
|
"mariadb",
|
||||||
"mysql",
|
"mysql",
|
||||||
|
"mssql",
|
||||||
"query builder",
|
"query builder",
|
||||||
"postgres",
|
"postgres",
|
||||||
"postgresql",
|
"postgresql",
|
||||||
"sql",
|
"sql",
|
||||||
"sqlite",
|
"sqlite",
|
||||||
"sqlite3"
|
"sqlite3",
|
||||||
|
"sqlserver"
|
||||||
],
|
],
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
|
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
|
||||||
@ -43,6 +45,7 @@
|
|||||||
"pg": "^6.0.0",
|
"pg": "^6.0.0",
|
||||||
"require-reload": "~0.2.2",
|
"require-reload": "~0.2.2",
|
||||||
"sqlite3": "^3.1.8",
|
"sqlite3": "^3.1.8",
|
||||||
|
"tedious": "^1.14.0",
|
||||||
"xregexp": "^3.0.0"
|
"xregexp": "^3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -53,6 +56,7 @@
|
|||||||
"globstar": "^1.0.0",
|
"globstar": "^1.0.0",
|
||||||
"happiness": "^7.1.2",
|
"happiness": "^7.1.2",
|
||||||
"istanbul": "~0.4.2",
|
"istanbul": "~0.4.2",
|
||||||
|
"jsdoc": "^3.4.3",
|
||||||
"mocha": "^3.0.0",
|
"mocha": "^3.0.0",
|
||||||
"npm-run-all": "^3.0.0",
|
"npm-run-all": "^3.0.0",
|
||||||
"nsp": "^2.2.1"
|
"nsp": "^2.2.1"
|
||||||
@ -65,6 +69,7 @@
|
|||||||
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
|
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
|
||||||
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
|
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
|
||||||
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
|
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
|
||||||
|
"postdocs": "jsdoc lib -r -d documentation",
|
||||||
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
|
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
|
||||||
"happy:src": "happiness \"lib/**/*.js\"",
|
"happy:src": "happiness \"lib/**/*.js\"",
|
||||||
"happy:tests": "happiness \"test/**/*.js\"",
|
"happy:tests": "happiness \"test/**/*.js\"",
|
||||||
|
@ -17,15 +17,9 @@ let qb = nodeQuery.getQuery();
|
|||||||
|
|
||||||
suite('Dblite adapter tests -', () => {
|
suite('Dblite adapter tests -', () => {
|
||||||
suiteSetup(done => {
|
suiteSetup(done => {
|
||||||
// Set up the sqlite database
|
qb.queryFile(`${__dirname}/../sql/sqlite.sql`)
|
||||||
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
.then(() => done())
|
||||||
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
.catch(e => done(e));
|
||||||
|
|
||||||
qb.query(createTest)
|
|
||||||
.then(() => qb.query(createJoin))
|
|
||||||
.then(() => {
|
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
|
@ -17,15 +17,9 @@ let qb = nodeQuery.getQuery();
|
|||||||
|
|
||||||
suite('Sqlite3 adapter tests -', () => {
|
suite('Sqlite3 adapter tests -', () => {
|
||||||
suiteSetup(done => {
|
suiteSetup(done => {
|
||||||
// Set up the sqlite database
|
qb.queryFile(`${__dirname}/../sql/sqlite.sql`)
|
||||||
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
.then(() => done())
|
||||||
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
.catch(e => done(e));
|
||||||
|
|
||||||
qb.query(createTest)
|
|
||||||
.then(() => qb.query(createJoin))
|
|
||||||
.then(() => {
|
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
|
Loading…
Reference in New Issue
Block a user