UNPKG

sql-client

Version:

A dirt-simple SQL client abstraction (currently) supporting PostgreSQL, MySQL and SQLite.

62 lines (45 loc) 1.88 kB
// Generated by CoffeeScript 2.6.0 (function() { var ConnectionFactory, MySQLClient, MySQLClientPool, MySQLConnectionFactory, SQLClient, SQLClientPool, mysql, 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; mysql = require('mysql'); MySQLConnectionFactory = class MySQLConnectionFactory extends ConnectionFactory { constructor() { super(...arguments); this.open_connection = this.open_connection.bind(this); this.close_connection = this.close_connection.bind(this); } open_connection(options, callback) { var connection; boundMethodCheck(this, MySQLConnectionFactory); connection = mysql.createConnection(options); return connection.connect((err) => { return callback(err, connection); }); } close_connection(connection, callback) { boundMethodCheck(this, MySQLConnectionFactory); if (typeof (connection != null ? connection.end : void 0) === 'function') { return connection.end(callback); } else { return super.close_connection(connection, callback); } } }; MySQLClient = class MySQLClient extends SQLClient { constructor(...options) { super(...options, new MySQLConnectionFactory()); } }; MySQLClientPool = class MySQLClientPool extends SQLClientPool { constructor(...options) { super(...options, new MySQLConnectionFactory()); } }; exports.MySQLConnectionFactory = MySQLConnectionFactory; exports.MySQLClient = MySQLClient; exports.MySQLClientPool = MySQLClientPool; }).call(this);