-
Notifications
You must be signed in to change notification settings - Fork 25
/
mssql-client.js
80 lines (60 loc) · 3.12 KB
/
mssql-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Generated by CoffeeScript 1.10.0
(function() {
let ConnectionFactory = require('sql-client/lib/connection-factory').ConnectionFactory;
let SQLClient = require('sql-client/lib/sql-client').SQLClient;
let SQLClientPool = require('sql-client/lib/sql-client-pool').SQLClientPool;
let mssql = require('mssql');
let bind = function (fn, me){ return function (){ return fn.apply(me, arguments); }; };
let extend = function (child, parent) { for (const 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; };
let hasProp = {}.hasOwnProperty;
let slice = [].slice;
let 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) {
let connection;
const 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) {
const request = new mssql.Request(connection);
return request.query(sql, function(err, recordset) {
callback(err, recordset);
});
};
return MSSQLConnectionFactory;
})(ConnectionFactory);
let MSSQLClient = (function (superClass) {
extend(MSSQLClient, superClass);
function MSSQLClient() {
const options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
MSSQLClient.__super__.constructor.apply(this, slice.call(options).concat([new MSSQLConnectionFactory()]));
}
return MSSQLClient;
})(SQLClient);
let MSSQLClientPool = (function (superClass) {
extend(MSSQLClientPool, superClass);
function MSSQLClientPool() {
const 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);