node-query/lib/adapters/Firebird.js

51 lines
1014 B
JavaScript
Raw Normal View History

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