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
|
||||
*
|
||||
* @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')({
|
||||
* driver: 'mysql',
|
||||
* 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';
|
||||
|
||||
const Pg = require('./Pg');
|
||||
const PgNative = require('./PgNative')
|
||||
|
||||
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';
|
||||
|
||||
module.exports = config => {
|
||||
const Implementation = (config.adapter && config.adapter === 'dblite')
|
||||
? require('./dblite')
|
||||
: require('./sqlite3');
|
||||
const Implementation = (config.native)
|
||||
? require('./sqlite3')
|
||||
: require('./dblite');
|
||||
|
||||
return new Implementation(config.connection);
|
||||
};
|
||||
|
@ -23,12 +23,14 @@
|
||||
"codeigniter",
|
||||
"mariadb",
|
||||
"mysql",
|
||||
"mssql",
|
||||
"query builder",
|
||||
"postgres",
|
||||
"postgresql",
|
||||
"sql",
|
||||
"sqlite",
|
||||
"sqlite3"
|
||||
"sqlite3",
|
||||
"sqlserver"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
|
||||
@ -43,6 +45,7 @@
|
||||
"pg": "^6.0.0",
|
||||
"require-reload": "~0.2.2",
|
||||
"sqlite3": "^3.1.8",
|
||||
"tedious": "^1.14.0",
|
||||
"xregexp": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -53,6 +56,7 @@
|
||||
"globstar": "^1.0.0",
|
||||
"happiness": "^7.1.2",
|
||||
"istanbul": "~0.4.2",
|
||||
"jsdoc": "^3.4.3",
|
||||
"mocha": "^3.0.0",
|
||||
"npm-run-all": "^3.0.0",
|
||||
"nsp": "^2.2.1"
|
||||
@ -65,6 +69,7 @@
|
||||
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
|
||||
"predocs": "globstar -- documentation build -f md -o API.md \"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:src": "happiness \"lib/**/*.js\"",
|
||||
"happy:tests": "happiness \"test/**/*.js\"",
|
||||
|
@ -17,15 +17,9 @@ let qb = nodeQuery.getQuery();
|
||||
|
||||
suite('Dblite adapter tests -', () => {
|
||||
suiteSetup(done => {
|
||||
// Set up the sqlite database
|
||||
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
||||
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
||||
|
||||
qb.query(createTest)
|
||||
.then(() => qb.query(createJoin))
|
||||
.then(() => {
|
||||
return done();
|
||||
});
|
||||
qb.queryFile(`${__dirname}/../sql/sqlite.sql`)
|
||||
.then(() => done())
|
||||
.catch(e => done(e));
|
||||
});
|
||||
|
||||
testRunner(qb);
|
||||
|
@ -17,15 +17,9 @@ let qb = nodeQuery.getQuery();
|
||||
|
||||
suite('Sqlite3 adapter tests -', () => {
|
||||
suiteSetup(done => {
|
||||
// Set up the sqlite database
|
||||
const createTest = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
||||
const createJoin = 'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
||||
|
||||
qb.query(createTest)
|
||||
.then(() => qb.query(createJoin))
|
||||
.then(() => {
|
||||
return done();
|
||||
});
|
||||
qb.queryFile(`${__dirname}/../sql/sqlite.sql`)
|
||||
.then(() => done())
|
||||
.catch(e => done(e));
|
||||
});
|
||||
|
||||
testRunner(qb);
|
||||
|
Loading…
Reference in New Issue
Block a user