87 lines
3.2 KiB
JavaScript
87 lines
3.2 KiB
JavaScript
// Generated by CoffeeScript 1.10.0
|
|
(function() {
|
|
var ConnectionFactory, SQLClient, SQLClientPool, MSSQLClient, MSSQLClientPool, MSSQLConnectionFactory, mssql,
|
|
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
hasProp = {}.hasOwnProperty,
|
|
slice = [].slice;
|
|
|
|
SQLClient = require('sql-client/lib/sql-client').SQLClient;
|
|
|
|
SQLClientPool = require('sql-client/lib/sql-client-pool').SQLClientPool;
|
|
|
|
ConnectionFactory = require('sql-client/lib/connection-factory').ConnectionFactory;
|
|
|
|
mssql = require('mssql');
|
|
|
|
MSSQLConnectionFactory = (function(superClass) {
|
|
extend(MSSQLConnectionFactory, superClass);
|
|
|
|
function MSSQLConnectionFactory() {
|
|
this.execute = bind(this.execute, this);
|
|
this.open_connection = bind(this.open_connection, this);
|
|
return MSSQLConnectionFactory.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
MSSQLConnectionFactory.prototype.open_connection = function(config, callback) {
|
|
var connection;
|
|
var pos = config.server.indexOf(':');
|
|
if (pos != -1) {
|
|
config.port = parseInt(config.server.substring(pos + 1), 10);
|
|
config.server = config.server.substring(0, pos);
|
|
}
|
|
|
|
return connection = new mssql.Connection(config, function (err) {
|
|
if (err != null) {
|
|
return callback(err);
|
|
} else {
|
|
return callback(null, connection);
|
|
}
|
|
}.bind(this));
|
|
};
|
|
|
|
MSSQLConnectionFactory.prototype.execute = function(connection, sql, bindvars, callback) {
|
|
var request = new mssql.Request(connection);
|
|
return request.query(sql, function(err, recordset) {
|
|
callback(err, recordset);
|
|
});
|
|
};
|
|
|
|
return MSSQLConnectionFactory;
|
|
|
|
})(ConnectionFactory);
|
|
|
|
MSSQLClient = (function(superClass) {
|
|
extend(MSSQLClient, superClass);
|
|
|
|
function MSSQLClient() {
|
|
var options;
|
|
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
MSSQLClient.__super__.constructor.apply(this, slice.call(options).concat([new MSSQLConnectionFactory()]));
|
|
}
|
|
|
|
return MSSQLClient;
|
|
|
|
})(SQLClient);
|
|
|
|
MSSQLClientPool = (function(superClass) {
|
|
extend(MSSQLClientPool, superClass);
|
|
|
|
function MSSQLClientPool() {
|
|
var options;
|
|
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
MSSQLClientPool.__super__.constructor.apply(this, slice.call(options).concat([new MSSQLConnectionFactory()]));
|
|
}
|
|
|
|
return MSSQLClientPool;
|
|
|
|
})(SQLClientPool);
|
|
|
|
exports.MSSQLConnectionFactory = MSSQLConnectionFactory;
|
|
|
|
exports.MSSQLClient = MSSQLClient;
|
|
|
|
exports.MSSQLClientPool = MSSQLClientPool;
|
|
|
|
}).call(this);
|