This commit is contained in:
Sky Morey 2015-12-15 16:50:47 -06:00
commit aa6cb2eb9c
5 changed files with 2343 additions and 2464 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,12 @@
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
@ -14,7 +20,7 @@ var Connection = (function (_EventEmitter) {
function Connection(connection) {
_classCallCheck(this, Connection);
_EventEmitter.call(this);
_get(Object.getPrototypeOf(Connection.prototype), 'constructor', this).call(this);
this.connection = connection;
// Flag indicating whether the connection is "managed",
@ -22,9 +28,12 @@ var Connection = (function (_EventEmitter) {
this.managed = false;
}
Connection.prototype.execute = function execute() {
return this._execute();
};
_createClass(Connection, [{
key: 'execute',
value: function execute() {
return this._execute();
}
}]);
return Connection;
})(_events.EventEmitter);

View File

@ -1,125 +0,0 @@
'use strict';
var SqlString = exports;
var helpers = require('../../helpers');
SqlString.escape = function (val, timeZone) {
if (val == null) {
return 'NULL';
}
switch (typeof val) {
case 'boolean':
return val ? 'true' : 'false';
case 'number':
return val + '';
}
if (val instanceof Date) {
val = SqlString.dateToString(val, timeZone || 'local');
}
if (Buffer.isBuffer(val)) {
return SqlString.bufferToString(val);
}
if (Array.isArray(val)) {
return SqlString.arrayToList(val, timeZone);
}
if (typeof val === 'object') {
try {
val = JSON.stringify(val);
} catch (e) {
helpers.warn(e);
val = val + '';
}
}
val = val.replace(/[\0\n\r\b\t\\\'\x1a]/g, function (s) {
switch (s) {
case '\u0000':
return '\\0';
case '\n':
return '\\n';
case '\r':
return '\\r';
case '\b':
return '\\b';
case '\t':
return '\\t';
case '\u001a':
return '\\Z';
case '\'':
return '\'\'';
default:
return '\\' + s;
}
});
return '\'' + val + '\'';
};
SqlString.arrayToList = function (array, timeZone) {
return array.map(function (v) {
if (Array.isArray(v)) return '(' + SqlString.arrayToList(v, timeZone) + ')';
return SqlString.escape(v, timeZone);
}).join(', ');
};
SqlString.format = function (sql, values, timeZone) {
values = values == null ? [] : [].concat(values);
var index = 0;
return sql.replace(/\?/g, function (match) {
if (index === values.length) {
return match;
}
var value = values[index++];
return SqlString.escape(value, timeZone);
});
};
SqlString.dateToString = function (date, timeZone) {
var dt = new Date(date);
if (timeZone !== 'local') {
var tz = convertTimezone(timeZone);
dt.setTime(dt.getTime() + dt.getTimezoneOffset() * 60000);
if (tz !== false) {
dt.setTime(dt.getTime() + tz * 60000);
}
}
var year = dt.getFullYear();
var month = zeroPad(dt.getMonth() + 1, 2);
var day = zeroPad(dt.getDate(), 2);
var hour = zeroPad(dt.getHours(), 2);
var minute = zeroPad(dt.getMinutes(), 2);
var second = zeroPad(dt.getSeconds(), 2);
var millisecond = zeroPad(dt.getMilliseconds(), 3);
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second + '.' + millisecond;
};
SqlString.bufferToString = function bufferToString(buffer) {
return 'X\'' + buffer.toString('hex') + '\'';
};
function zeroPad(number, length) {
number = number.toString();
while (number.length < length) {
number = '0' + number;
}
return number;
}
function convertTimezone(tz) {
if (tz === 'Z') return 0;
var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
if (m) {
return (m[1] === '-' ? -1 : 1) * (parseInt(m[2], 10) + (m[3] ? parseInt(m[3], 10) : 0) / 60) * 60;
}
return false;
}

View File

@ -1,6 +1,8 @@
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = parseConnectionString;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
@ -30,7 +32,7 @@ function parseConnectionString(str) {
}
return {
client: protocol,
connection: protocol === 'postgres' ? _pgConnectionString.parse(str) : connectionObject(parsed)
connection: protocol === 'postgres' ? (0, _pgConnectionString.parse)(str) : connectionObject(parsed)
};
}

View File

@ -33,11 +33,11 @@ assign(Client_MSSQL.prototype, {
_driver: function() {
return require('mssql');
},
Transaction: Transaction,
Formatter: Formatter,
QueryCompiler: QueryCompiler,
SchemaCompiler: SchemaCompiler,
@ -64,13 +64,13 @@ assign(Client_MSSQL.prototype, {
});
});
},
// Used to explicitly close a connection, called internally by the pool
// when a connection times out or the pool is shutdown.
destroyRawConnection: function(connection, cb) {
connection.close(cb);
},
// Position the bindings for the query.
positionBindings: function(sql) {
var questionCount = -1
@ -79,7 +79,7 @@ assign(Client_MSSQL.prototype, {
return '@p' + questionCount
})
},
prepBindings: function(bindings) {
return _.map(bindings, function(value) {
if (value === undefined) {
@ -88,7 +88,7 @@ assign(Client_MSSQL.prototype, {
return value
}, this)
},
// Grab a connection, run the query via the MSSQL streaming interface,
// and pass that through to the stream we've sent back to the client.
_stream: function(connection, obj, stream, options) {
@ -113,7 +113,7 @@ assign(Client_MSSQL.prototype, {
}
}
req.pipe(stream)
req.query(sql)
req.query(sql)
})
},
@ -140,7 +140,7 @@ assign(Client_MSSQL.prototype, {
if (err) return rejecter(err)
obj.response = recordset[0]
resolver(obj)
})
})
})
},
@ -176,7 +176,7 @@ assign(Client_MSSQL.prototype, {
return response
}
}
})
// MSSQL Specific error handler
@ -188,4 +188,4 @@ function connectionErrorHandler(client, connection, err) {
}
}
module.exports = Client_MSSQL
module.exports = Client_MSSQL