sql-client
Version:
A dirt-simple SQL client abstraction (currently) supporting PostgreSQL, MySQL and SQLite.
74 lines (57 loc) • 2.12 kB
JavaScript
// Generated by CoffeeScript 2.6.0
(function() {
var ConnectionFactory, SQLClient, SQLClientPool, SQLite3Client, SQLite3ClientPool, SQLite3ConnectionFactory, sqlite3,
boundMethodCheck = function(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new Error('Bound instance method accessed before binding'); } };
SQLClient = require('./sql-client').SQLClient;
SQLClientPool = require('./sql-client-pool').SQLClientPool;
ConnectionFactory = require('./connection-factory').ConnectionFactory;
sqlite3 = require('sqlite3').verbose();
SQLite3ConnectionFactory = class SQLite3ConnectionFactory extends ConnectionFactory {
constructor() {
super(...arguments);
this.open_connection = this.open_connection.bind(this);
this.execute = this.execute.bind(this);
}
open_connection(filename, mode, callback) {
var cb, db;
boundMethodCheck(this, SQLite3ConnectionFactory);
if (typeof mode === 'function' && (callback == null)) {
callback = mode;
mode = null;
}
db = null;
cb = (err) => {
if (err != null) {
return callback(err);
} else {
return callback(null, db);
}
};
if (mode != null) {
return db = new sqlite3.Database(filename, mode, cb);
} else {
return db = new sqlite3.Database(filename, cb);
}
}
execute(db, sql, bindvars, callback) {
boundMethodCheck(this, SQLite3ConnectionFactory);
if (bindvars == null) {
bindvars = [];
}
return db.all(sql, bindvars, callback);
}
};
SQLite3Client = class SQLite3Client extends SQLClient {
constructor(...options) {
super(...options, new SQLite3ConnectionFactory());
}
};
SQLite3ClientPool = class SQLite3ClientPool extends SQLClientPool {
constructor(...options) {
super(...options, new SQLite3ConnectionFactory());
}
};
exports.SQLite3ConnectionFactory = SQLite3ConnectionFactory;
exports.SQLite3Client = SQLite3Client;
exports.SQLite3ClientPool = SQLite3ClientPool;
}).call(this);