2016-11-10 20:15:16 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Adapter = require('../Adapter');
|
|
|
|
const fb = require('node-firebird');
|
|
|
|
|
|
|
|
class Firebird extends Adapter {
|
|
|
|
|
2016-11-10 22:10:45 -05:00
|
|
|
constructor (config) {
|
2016-11-10 20:15:16 -05:00
|
|
|
super({});
|
2016-11-10 22:10:45 -05:00
|
|
|
this.instance = new Promise((resolve, reject) => {
|
|
|
|
fb.attach(config, (err, instance) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(instance)
|
|
|
|
});
|
2016-11-10 20:15:16 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2016-11-10 22:10:45 -05:00
|
|
|
* @return {Promise} - Returns a promise if no callback is provided
|
2016-11-10 20:15:16 -05:00
|
|
|
*/
|
2016-11-10 22:10:45 -05:00
|
|
|
execute (sql, params) {
|
|
|
|
return this.instance.then(conn => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2016-11-14 20:23:27 -05:00
|
|
|
conn.query(sql, params, (err, result) => {
|
2016-11-10 22:10:45 -05:00
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(result);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2016-11-10 20:15:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the current database connection
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2016-11-10 22:10:45 -05:00
|
|
|
close () {
|
|
|
|
this.instance.then(conn => conn.detach());
|
2016-11-10 20:15:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Firebird;
|