Revert "Remove Firebird."

This reverts commit 8f0b394d3c.
This commit is contained in:
Timothy Warren 2016-11-10 20:15:16 -05:00
parent 692c07ba74
commit 7b2482ad99
3 changed files with 160 additions and 0 deletions

58
lib/adapters/Firebird.js Normal file
View File

@ -0,0 +1,58 @@
'use strict';
const Adapter = require('../Adapter');
const getArgs = require('getargs');
const fb = require('node-firebird');
class Firebird extends Adapter {
constructor(config) {
super({});
fb.attach(config, (err, instance) => {
this.instance = instance;
if (err) {
throw new Error(err);
}
});
}
/**
* 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
* @param {Function} [callback] - Callback to run when a response is recieved
* @return {void|Promise} - Returns a promise if no callback is provided
*/
execute(/*sql, params, callback*/) {
let args = getArgs('sql:string, [params], [callback]:function', arguments);
if (! args.callback) {
//return instance.queryAsync(args.sql, args.params);
if (! args.callback) {
return new Promise((resolve, reject) => {
this.instance.query(args.sql, args.params, (err, result) => {
if (err) {
return reject(err);
}
return resolve(result);
});
});
}
}
return this.instance.query(args.sql, args.params, args.callback);
}
/**
* Close the current database connection
* @return {void}
*/
close() {
this.instance.detach();
}
}
module.exports = Firebird;

46
lib/drivers/Firebird.js Normal file
View File

@ -0,0 +1,46 @@
'use strict';
let helpers = require('../helpers');
/**
* Driver for Firebird databases
*
* @module drivers/firebird
*/
module.exports = (() => {
delete require.cache[require.resolve('../Driver')];
let driver = require('../Driver');
driver.hasTruncate = false;
/**
* Set the limit clause
* @param {String} origSql - SQL statement to modify
* @param {Number} limit - Maximum number of rows to fetch
* @param {Number|null} offset - Number of rows to skip
* @return {String} - Modified SQL statement
*/
driver.limit = (origSql, limit, offset) => {
let sql = `FIRST ${limit}`;
if (helpers.isNumber(offset))
{
sql += ` SKIP ${offset}`;
}
return origSql.replace(/SELECT/i, `SELECT ${sql}`);
};
/**
* SQL to insert a group of rows
*
* @return {void}
* @throws {Error}
*/
driver.insertBatch = () => {
throw new Error('Not Implemented');
};
return driver;
})();

View File

@ -0,0 +1,56 @@
'use strict';
(() => {
// Load the test base
const path = require('path');
const reload = require('require-reload')(require);
const testBase = reload('../base');
const promisify = require('../../lib/promisify');
const expect = reload('chai').expect;
const testRunner = testBase.testRunner;
const promiseTestRunner = 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');
});
//---------------------------------------------------------------------------
// Callback Tests
//---------------------------------------------------------------------------
testRunner(qb, (err, done) => {
expect(err).is.not.ok;
done();
});
//---------------------------------------------------------------------------
// Promise Tests
//---------------------------------------------------------------------------
qb.adapter.execute(qb.driver.truncate('create_test')).then(() => {
promiseTestRunner(qb);
});
suiteTeardown(() => {
qb.end();
});
});
})();