25 changed files with 321 additions and 175 deletions
@ -0,0 +1,29 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org |
||||
|
||||
# top-most EditorConfig file |
||||
root = true |
||||
|
||||
# Unix-style newlines with a newline ending every file |
||||
[*] |
||||
end_of_line = lf |
||||
insert_final_newline = true |
||||
|
||||
# Matches multiple files with brace expansion notation |
||||
# Set default charset |
||||
[*] |
||||
charset = utf-8 |
||||
|
||||
# Tab indentation (no size specified) |
||||
[*] |
||||
indent_style = tab |
||||
indent_size = 4 |
||||
|
||||
# Indentation override for all JS under lib directory |
||||
[*.js] |
||||
indent_size = 2 |
||||
|
||||
# Matches the exact files either package.json or .travis.yml |
||||
[*.yml] |
||||
indent_style = space |
||||
indent_size = 2 |
||||
|
@ -0,0 +1,8 @@
|
||||
'use strict'; |
||||
|
||||
const NodeFirebird = require('./node-firebird'); |
||||
|
||||
module.exports = config => { |
||||
return new NodeFirebird(config.connection); |
||||
}; |
||||
|
@ -1,3 +0,0 @@
|
||||
'use strict'; |
||||
|
||||
module.exports = require('./Mysql'); |
@ -0,0 +1,3 @@
|
||||
'use strict'; |
||||
|
||||
module.exports = require('../Mysql'); |
@ -0,0 +1,7 @@
|
||||
'use strict'; |
||||
|
||||
const Mysql2 = require('./mysql2'); |
||||
|
||||
module.exports = config => { |
||||
return new Mysql2(config.connection); |
||||
}; |
@ -0,0 +1,7 @@
|
||||
'use strict'; |
||||
|
||||
const Pg = require('./pg'); |
||||
|
||||
module.exports = config => { |
||||
return new Pg(config.connection); |
||||
}; |
@ -0,0 +1,67 @@
|
||||
'use strict'; |
||||
|
||||
const Adapter = require('../../Adapter'); |
||||
const Result = require('../../Result'); |
||||
const helpers = require('../../helpers'); |
||||
const dbliteAdapter = require('dblite'); |
||||
|
||||
class SqliteDblite extends Adapter { |
||||
constructor (config) { |
||||
let file = (helpers.isString(config)) ? config : config.file; |
||||
|
||||
const instance = new Promise((resolve, reject) => { |
||||
let conn = dbliteAdapter(file); |
||||
|
||||
// Stop the stupid 'bye bye' message being output
|
||||
conn.on('close', () => {}); |
||||
|
||||
conn.on('error', err => { |
||||
reject(err); |
||||
}); |
||||
|
||||
// Make sure to actually pass on the connection!
|
||||
return resolve(conn); |
||||
}); |
||||
|
||||
super(instance); |
||||
} |
||||
|
||||
/** |
||||
* Run the sql query as a prepared statement |
||||
* |
||||
* @param {String} sql - The sql with placeholders |
||||
* @param {Array} params - The values to insert into the query |
||||
* @return {Promise} - Returns a promise if no callback is provided |
||||
*/ |
||||
execute (sql, params) { |
||||
return this.instance.then(conn => new Promise((resolve, reject) => { |
||||
return conn.query(sql, params, (err, rows) => { |
||||
if (err) { |
||||
return reject(err); |
||||
} |
||||
return resolve(this.transformResult(rows)); |
||||
}); |
||||
})); |
||||
} |
||||
|
||||
/** |
||||
* Transform the adapter's result into a standard format |
||||
* |
||||
* @param {*} originalResult - the original result object from the driver |
||||
* @return {Result} - the new result object |
||||
*/ |
||||
transformResult (originalResult) { |
||||
return new Result(originalResult); |
||||
} |
||||
|
||||
/** |
||||
* Close the current database connection |
||||
* |
||||
* @return {void} |
||||
*/ |
||||
close () { |
||||
this.instance.then(conn => conn.close()); |
||||
} |
||||
} |
||||
|
||||
module.exports = SqliteDblite; |
@ -0,0 +1,10 @@
|
||||
'use strict'; |
||||
|
||||
module.exports = config => { |
||||
const Implementation = (config.adapter && config.adapter === 'dblite') |
||||
? require('./dblite') |
||||
: require('./sqlite3'); |
||||
|
||||
return new Implementation(config.connection); |
||||
}; |
||||
|
@ -0,0 +1,38 @@
|
||||
/* eslint-env node, mocha */ |
||||
'use strict'; |
||||
|
||||
// Load the test base
|
||||
const path = require('path'); |
||||
const reload = require('require-reload')(require); |
||||
const testBase = reload('../base'); |
||||
const expect = testBase.expect; |
||||
const testRunner = testBase.promiseTestRunner; |
||||
|
||||
// Skip on CI
|
||||
if (!(process.env.CI || process.env.TRAVIS)) { |
||||
// Load the test config file
|
||||
let adapterName = 'node-firebird'; |
||||
const config = reload('../config.json')[adapterName]; |
||||
config.connection.database = path.join(__dirname, config.connection.database); |
||||
let nodeQuery = reload('../../lib/NodeQuery')(config); |
||||
|
||||
let qb = nodeQuery.getQuery(); |
||||
|
||||
suite('Firebird adapter tests -', () => { |
||||
test('nodeQuery.getQuery = nodeQuery.init', () => { |
||||
expect(nodeQuery.getQuery()) |
||||
.to.be.deep.equal(qb); |
||||
}); |
||||
test('insertBatch throws error', () => { |
||||
expect(() => { |
||||
qb.driver.insertBatch('create_test', []); |
||||
}).to.throw(Error, 'Not Implemented'); |
||||
}); |
||||
|
||||
testRunner(qb); |
||||
|
||||
suiteTeardown(() => { |
||||
qb.end(); |
||||
}); |
||||
}); |
||||
} |
@ -1,40 +0,0 @@
|
||||
'use strict'; |
||||
|
||||
// Load the test base
|
||||
const path = require('path'); |
||||
const reload = require('require-reload')(require); |
||||
const testBase = reload('../base'); |
||||
const expect = testBase.expect; |
||||
const testRunner = testBase.promiseTestRunner; |
||||
|
||||
// Skip on CI
|
||||
if (process.env.CI || process.env.TRAVIS) { |
||||
return; |
||||
} |
||||
|
||||
// Load the test config file
|
||||
let adapterName = 'node-firebird'; |
||||
let Firebird = reload(adapterName); |
||||
const config = reload('../config.json')[adapterName]; |
||||
config.connection.database = path.join(__dirname, config.connection.database); |
||||
let nodeQuery = reload('../../lib/NodeQuery')(config); |
||||
|
||||
let qb = nodeQuery.getQuery(); |
||||
|
||||
suite('Firebird adapter tests -', () => { |
||||
test('nodeQuery.getQuery = nodeQuery.init', () => { |
||||
expect(nodeQuery.getQuery()) |
||||
.to.be.deep.equal(qb); |
||||
}); |
||||
test('insertBatch throws error', () => { |
||||
expect(() => { |
||||
qb.driver.insertBatch('create_test', []); |
||||
}).to.throw(Error, 'Not Implemented'); |
||||
}); |
||||
|
||||
testRunner(qb); |
||||
|
||||
suiteTeardown(() => { |
||||
qb.end(); |
||||
}); |
||||
}); |
@ -0,0 +1,63 @@
|
||||
/* eslint-env node, mocha */ |
||||
'use strict'; |
||||
|
||||
// Load the test base
|
||||
const reload = require('require-reload')(require); |
||||
reload.emptyCache(); |
||||
const testBase = reload('../base'); |
||||
const expect = testBase.expect; |
||||
const testRunner = testBase.promiseTestRunner; |
||||
|
||||
// Load the test config file
|
||||
const config = testBase.config; |
||||
|
||||
// Set up the query builder object
|
||||
let nodeQuery = require('../../lib/NodeQuery')(config.sqlite3); |
||||
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(); |
||||
}); |
||||
}); |
||||
|
||||
testRunner(qb); |
||||
test('Promise - Select with function and argument in WHERE clause', () => { |
||||
let promise = qb.select('id') |
||||
.from('create_test') |
||||
.where('id', 'ABS(-88)') |
||||
.get(); |
||||
|
||||
expect(promise).to.be.fulfilled; |
||||
}); |
||||
test('Promise - Test Insert Batch', () => { |
||||
let data = [ |
||||
{ |
||||
id: 544, |
||||
key: 3, |
||||
val: Buffer.from('7') |
||||
}, { |
||||
id: 89, |
||||
key: 34, |
||||
val: Buffer.from('10 o\'clock') |
||||
}, { |
||||
id: 48, |
||||
key: 403, |
||||
val: Buffer.from('97') |
||||
} |
||||
]; |
||||
|
||||
let promise = qb.insertBatch('create_test', data); |
||||
expect(promise).to.be.fulfilled; |
||||
}); |
||||
suiteTeardown(() => { |
||||
qb.end(); |
||||
}); |
||||
}); |
Loading…
Reference in new issue