Socket
Socket
Sign inDemoInstall

mssql

Package Overview
Dependencies
Maintainers
1
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mssql - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

23

lib/datatypes.js

@@ -197,2 +197,25 @@ // Generated by CoffeeScript 1.7.1

module.exports.declare = function(type, options) {
var _ref, _ref1, _ref2, _ref3, _ref4;
switch (type) {
case TYPES.VarChar:
case TYPES.NVarChar:
case TYPES.VarBinary:
return "" + type.declaration + " (" + ((_ref = options.length) != null ? _ref : 'MAX') + ")";
case TYPES.Char:
case TYPES.NChar:
case TYPES.Binary:
return "" + type.declaration + " (" + ((_ref1 = options.length) != null ? _ref1 : 1) + ")";
case TYPES.Decimal:
case TYPES.Numeric:
return "" + ((_ref2 = type.precision) != null ? _ref2 : 18) + " (" + ((_ref3 = options.scale) != null ? _ref3 : 0) + ")";
case TYPES.Time:
case TYPES.DateTime2:
case TYPES.DateTimeOffset:
return "" + type.declaration + " (" + ((_ref4 = options.scale) != null ? _ref4 : 7) + ")";
default:
return type.declaration;
}
};
}).call(this);

394

lib/main.js
// Generated by CoffeeScript 1.7.1
(function() {
var Connection, ConnectionError, DRIVERS, EventEmitter, ISOLATION_LEVEL, Request, RequestError, TYPES, Table, Transaction, TransactionError, getTypeByValue, global_connection, key, map, util, value,
var Connection, ConnectionError, DRIVERS, EventEmitter, ISOLATION_LEVEL, PreparedStatement, PreparedStatementError, Request, RequestError, TYPES, Table, Transaction, TransactionError, declare, getTypeByValue, global_connection, key, map, util, value, _ref,
__hasProp = {}.hasOwnProperty,

@@ -12,3 +12,3 @@ __extends = 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; },

TYPES = require('./datatypes').TYPES;
_ref = require('./datatypes'), TYPES = _ref.TYPES, declare = _ref.declare;

@@ -151,3 +151,3 @@ ISOLATION_LEVEL = require('./isolationlevel');

function Connection(config, callback) {
var err, _base, _base1, _base2, _ref;
var err, _base, _base1, _base2, _ref1;
this.config = config;

@@ -167,3 +167,3 @@ if ((_base = this.config).driver == null) {

}
if (_ref = this.config.driver, __indexOf.call(DRIVERS, _ref) >= 0) {
if (_ref1 = this.config.driver, __indexOf.call(DRIVERS, _ref1) >= 0) {
this.driver = this.initializeDriver(require("./" + this.config.driver));

@@ -308,2 +308,309 @@ if (module.exports.fix) {

/*
Class PreparedStatement.
IMPORTANT: Rememeber that each prepared statement means one reserved connection from the pool. Don't forget to unprepare a prepared statement!
@property {Connection} connection Reference to used connection.
@property {String} statement Prepared SQL statement.
*/
PreparedStatement = (function(_super) {
__extends(PreparedStatement, _super);
PreparedStatement.prototype._pooledConnection = null;
PreparedStatement.prototype._queue = null;
PreparedStatement.prototype._working = false;
PreparedStatement.prototype._handle = 0;
PreparedStatement.prototype.connection = null;
PreparedStatement.prototype.transaction = null;
PreparedStatement.prototype.prepared = false;
PreparedStatement.prototype.statement = null;
PreparedStatement.prototype.parameters = null;
/*
Create new Prepared Statement.
@param {String} statement SQL statement.
@param {Connection} [connection] If ommited, global connection is used instead.
*/
function PreparedStatement(connection) {
if (connection instanceof Transaction) {
this.transaction = connection;
this.connection = connection.connection;
} else if (connection instanceof Connection) {
this.connection = connection;
} else {
this.connection = global_connection;
}
this._queue = [];
this.parameters = {};
}
/*
Add an input parameter to the prepared statement.
**Example:**
```
statement.input('input_parameter', sql.Int);
statement.input('input_parameter', sql.VarChar(50));
```
@param {String} name Name of the input parameter without @ char.
@param {*} type SQL data type of input parameter.
@returns {PreparedStatement}
*/
PreparedStatement.prototype.input = function(name, type) {
if (arguments.length < 2) {
throw new PreparedStatementError("Invalid number of arguments. 2 arguments expected.", 'EARGS');
}
if (type instanceof Function) {
type = type();
}
this.parameters[name] = {
name: name,
type: type.type,
io: 1,
length: type.length,
scale: type.scale,
precision: type.precision
};
return this;
};
/*
Add an output parameter to the prepared statement.
**Example:**
```
statement.output('output_parameter', sql.Int);
statement.output('output_parameter', sql.VarChar(50));
```
@param {String} name Name of the output parameter without @ char.
@param {*} type SQL data type of output parameter.
@returns {PreparedStatement}
*/
PreparedStatement.prototype.output = function(name, type) {
if (arguments.length < 2) {
throw new PreparedStatementError("Invalid number of arguments. 2 arguments expected.", 'EARGS');
}
if (type instanceof Function) {
type = type();
}
this.parameters[name] = {
name: name,
type: type.type,
io: 2,
length: type.length,
scale: type.scale,
precision: type.precision
};
return this;
};
/*
Prepare a statement.
@property {String} [statement] SQL statement to prepare.
@callback [callback] A callback which is called after preparation has completed, or an error has occurred.
@param {Error} err Error on error, otherwise null.
@returns {PreparedStatement}
*/
PreparedStatement.prototype.prepare = function(statement, callback) {
var done;
if (this._pooledConnection) {
if (typeof callback === "function") {
callback(new PreparedStatementError("Statement is already prepared."));
}
return this;
}
if (typeof statement === 'function') {
callback = statement;
statement = void 0;
}
if (statement != null) {
this.statement = statement;
}
done = (function(_this) {
return function(err, connection) {
var name, param, req;
if (err) {
return typeof callback === "function" ? callback(err) : void 0;
}
_this._pooledConnection = connection;
req = new Request(_this);
req.output('handle', TYPES.Int);
req.input('params', TYPES.NVarChar, ((function() {
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref1) {
param = _ref1[name];
_results.push("@" + name + " " + (declare(param.type, param)) + (param.io === 2 ? " output" : ""));
}
return _results;
}).call(_this)).join(','));
req.input('stmt', TYPES.NVarChar, _this.statement);
return req.execute('sp_prepare', function(err) {
if (err) {
if (_this.transaction) {
_this.transaction.next();
} else {
_this.connection.pool.release(_this._pooledConnection);
_this._pooledConnection = null;
}
return typeof callback === "function" ? callback(err) : void 0;
}
_this._handle = req.parameters.handle.value;
return typeof callback === "function" ? callback(null) : void 0;
});
};
})(this);
if (this.transaction) {
if (!this.transaction._pooledConnection) {
if (typeof callback === "function") {
callback(new PreparedStatementError("Transaction has not started. Call begin() first."));
}
return this;
}
this.transaction.queue(done);
} else {
this.connection.pool.acquire(done);
}
return this;
};
/*
Execute next request in queue.
@private
@returns {PreparedStatement}
*/
PreparedStatement.prototype.next = function() {
if (this._queue.length) {
this._queue.shift()(null, this._pooledConnection);
} else {
this._working = false;
}
return this;
};
/*
Add request to queue for connection. If queue is empty, execute the request immediately.
@private
@callback callback A callback to call when connection in ready to execute request.
@param {Error} err Error on error, otherwise null.
@param {*} conn Internal driver's connection.
@returns {PreparedStatement}
*/
PreparedStatement.prototype.queue = function(callback) {
if (!this._pooledConnection) {
callback(new PreparedStatementError("Statement is not prepared. Call prepare() first."));
return this;
}
if (this._working) {
this._queue.push(callback);
} else {
this._working = true;
callback(null, this._pooledConnection);
}
return this;
};
/*
Execute a prepared statement.
@property {String} values An object whose names correspond to the names of parameters that were added to the prepared statement before it was prepared.
@callback [callback] A callback which is called after execution has completed, or an error has occurred.
@param {Error} err Error on error, otherwise null.
@returns {Request}
*/
PreparedStatement.prototype.execute = function(values, callback) {
var name, param, req, _ref1;
req = new Request(this);
req.input('handle', TYPES.Int, this._handle);
_ref1 = this.parameters;
for (name in _ref1) {
param = _ref1[name];
req.parameters[name] = {
name: name,
type: param.type,
io: param.io,
value: values[name],
length: param.length,
scale: param.scale,
precision: param.precision
};
}
req.execute('sp_execute', callback);
return req;
};
/*
Unprepare a prepared statement.
@callback [callback] A callback which is called after unpreparation has completed, or an error has occurred.
@param {Error} err Error on error, otherwise null.
@returns {PreparedStatement}
*/
PreparedStatement.prototype.unprepare = function(callback) {
var done, req;
if (!this._pooledConnection) {
if (typeof callback === "function") {
callback(new PreparedStatementError("Statement is not prepared. Call prepare() first."));
}
return this;
}
done = (function(_this) {
return function(err) {
if (err) {
return typeof callback === "function" ? callback(err) : void 0;
}
if (_this.transaction) {
_this.transaction.next();
} else {
_this.connection.pool.release(_this._pooledConnection);
_this._pooledConnection = null;
}
_this._handle = 0;
return typeof callback === "function" ? callback(null) : void 0;
};
})(this);
req = new Request(this);
req.input('handle', TYPES.Int, this._handle);
req.execute('sp_unprepare', done);
return this;
};
return PreparedStatement;
})(EventEmitter);
/*
Class Transaction.

@@ -331,2 +638,4 @@

Transaction.prototype.connection = null;
Transaction.prototype.isolationLevel = ISOLATION_LEVEL.READ_COMMITTED;

@@ -338,3 +647,3 @@

@param {Connection} connection If ommited, global connection is used instead.
@param {Connection} [connection] If ommited, global connection is used instead.
*/

@@ -398,2 +707,8 @@

}
if (this._working) {
if (typeof callback === "function") {
callback(new TransactionError("Can't commit transaction. There is a request in progress."));
}
return this;
}
this.connection.driver.Transaction.prototype.commit.call(this, (function(_this) {

@@ -420,6 +735,7 @@ return function(err) {

if (this._queue.length) {
return this._queue.shift()(null, this._pooledConnection);
this._queue.shift()(null, this._pooledConnection);
} else {
return this._working = false;
this._working = false;
}
return this;
};

@@ -444,7 +760,8 @@

if (this._working) {
return this._queue.push(callback);
this._queue.push(callback);
} else {
this._working = true;
return callback(null, this._pooledConnection);
callback(null, this._pooledConnection);
}
return this;
};

@@ -479,2 +796,8 @@

}
if (this._working) {
if (typeof callback === "function") {
callback(new TransactionError("Can't rollback transaction. There is a request in progress."));
}
return this;
}
this.connection.driver.Transaction.prototype.rollback.call(this, (function(_this) {

@@ -518,2 +841,4 @@ return function(err) {

Request.prototype.pstatement = null;
Request.prototype.parameters = null;

@@ -538,2 +863,5 @@

this.connection = connection.connection;
} else if (connection instanceof PreparedStatement) {
this.pstatement = connection;
this.connection = connection.connection;
} else if (connection instanceof Connection) {

@@ -553,3 +881,9 @@ this.connection = connection;

Request.prototype._acquire = function(callback) {
return this.connection.driver.Request.prototype._acquire.call(this, callback);
if (this.transaction) {
return this.transaction.queue(callback);
} else if (this.pstatement) {
return this.pstatement.queue(callback);
} else {
return this.connection.pool.acquire(callback);
}
};

@@ -563,3 +897,9 @@

Request.prototype._release = function(connection) {
return this.connection.driver.Request.prototype._release.call(this, connection);
if (this.transaction) {
return this.transaction.next();
} else if (this.pstatement) {
return this.pstatement.next();
} else {
return this.connection.pool.release(connection);
}
};

@@ -862,3 +1202,31 @@

PreparedStatementError = (function(_super) {
__extends(PreparedStatementError, _super);
function PreparedStatementError(message, code) {
var err;
if (!(this instanceof PreparedStatementError)) {
if (message instanceof Error) {
err = new PreparedStatementError(message.message, message.code);
err.originalError = message;
Error.captureStackTrace(err, arguments.callee);
return err;
} else {
err = new PreparedStatementError(message);
Error.captureStackTrace(err, arguments.callee);
return err;
}
}
this.name = this.constructor.name;
this.message = message;
this.code = code;
PreparedStatementError.__super__.constructor.call(this);
Error.captureStackTrace(this, this.constructor);
}
return PreparedStatementError;
})(Error);
/*

@@ -898,2 +1266,4 @@ Open global connection.

module.exports.PreparedStatement = PreparedStatement;
module.exports.ConnectionError = ConnectionError;

@@ -905,2 +1275,4 @@

module.exports.PreparedStatementError = PreparedStatementError;
module.exports.ISOLATION_LEVEL = ISOLATION_LEVEL;

@@ -907,0 +1279,0 @@

147

lib/msnodesql.js
// Generated by CoffeeScript 1.7.1
(function() {
var CONNECTION_STRING_NAMED_INSTANCE, CONNECTION_STRING_PORT, DECLARATIONS, EMPTY_BUFFER, ISOLATION_LEVEL, Pool, TYPES, UDT, castParameter, createColumns, isolationLevelDeclaration, msnodesql, typeDeclaration, util, valueCorrection,
var CONNECTION_STRING_NAMED_INSTANCE, CONNECTION_STRING_PORT, DECLARATIONS, EMPTY_BUFFER, ISOLATION_LEVEL, Pool, TYPES, UDT, castParameter, createColumns, declare, isolationLevelDeclaration, msnodesql, util, valueCorrection, _ref,
__hasProp = {}.hasOwnProperty,

@@ -13,3 +13,3 @@ __extends = 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; };

TYPES = require('./datatypes').TYPES;
_ref = require('./datatypes'), TYPES = _ref.TYPES, declare = _ref.declare;

@@ -131,27 +131,2 @@ UDT = require('./udt').PARSERS;

typeDeclaration = function(type, options) {
var _ref, _ref1;
switch (type) {
case TYPES.VarChar:
case TYPES.NVarChar:
case TYPES.VarBinary:
return "" + type.declaration + " (MAX)";
case TYPES.Char:
case TYPES.NChar:
case TYPES.Binary:
return "" + type.declaration + " (" + ((_ref = options.length) != null ? _ref : 1) + ")";
case TYPES.Time:
case TYPES.DateTime2:
case TYPES.DateTimeOffset:
return "" + type.declaration + " (" + ((_ref1 = options.scale) != null ? _ref1 : 7) + ")";
default:
return type.declaration;
}
};
/*
@ignore
*/
isolationLevelDeclaration = function(type) {

@@ -211,3 +186,3 @@ switch (type) {

MsnodesqlConnection.prototype.connect = function(config, callback) {
var cfg, cfg_pool, defaultConnectionString, key, value, _ref, _ref1;
var cfg, cfg_pool, defaultConnectionString, key, value, _ref1, _ref2;
defaultConnectionString = CONNECTION_STRING_PORT;

@@ -218,6 +193,6 @@ if (config.options.instanceName != null) {

cfg = {
connectionString: (_ref = config.connectionString) != null ? _ref : defaultConnectionString
connectionString: (_ref1 = config.connectionString) != null ? _ref1 : defaultConnectionString
};
cfg.connectionString = cfg.connectionString.replace(new RegExp('#{([^}]*)}', 'g'), function(p) {
var key, _ref1;
var key, _ref2;
key = p.substr(2, p.length - 3);

@@ -233,3 +208,3 @@ if (key === 'instance') {

} else {
return (_ref1 = config[key]) != null ? _ref1 : '';
return (_ref2 = config[key]) != null ? _ref2 : '';
}

@@ -263,5 +238,5 @@ });

if (config.pool) {
_ref1 = config.pool;
for (key in _ref1) {
value = _ref1[key];
_ref2 = config.pool;
for (key in _ref2) {
value = _ref2[key];
cfg_pool[key] = value;

@@ -347,20 +322,2 @@ }

MsnodesqlRequest.prototype.connection = null;
MsnodesqlRequest.prototype._acquire = function(callback) {
if (this.transaction) {
return this.transaction.queue(callback);
} else {
return this.connection.pool.acquire(callback);
}
};
MsnodesqlRequest.prototype._release = function(connection) {
if (this.transaction) {
return this.transaction.next();
} else {
return this.connection.pool.release(connection);
}
};
MsnodesqlRequest.prototype.query = function(command, callback) {

@@ -391,8 +348,8 @@ var columns, handleOutput, input, name, output, param, recordset, recordsets, row, sets, started;

input = (function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
_results.push("@" + param.name + " " + (typeDeclaration(param.type, param)));
for (name in _ref1) {
param = _ref1[name];
_results.push("@" + param.name + " " + (declare(param.type, param)));
}

@@ -402,7 +359,7 @@ return _results;

sets = (function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
for (name in _ref1) {
param = _ref1[name];
if (param.io === 1) {

@@ -415,7 +372,7 @@ _results.push("set @" + param.name + "=?");

output = (function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
for (name in _ref1) {
param = _ref1[name];
if (param.io === 2) {

@@ -440,7 +397,7 @@ _results.push("@" + param.name + " as '" + param.name + "'");

req = connection.queryRaw(command, (function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
for (name in _ref1) {
param = _ref1[name];
if (param.io === 1) {

@@ -515,3 +472,3 @@ _results.push(castParameter(param.value, param.type));

return req.once('done', function() {
var elapsed, last, _ref, _ref1;
var elapsed, last, _ref1, _ref2;
if (!_this.nested) {

@@ -528,6 +485,6 @@ if (recordset) {

if (handleOutput) {
last = (_ref = recordsets.pop()) != null ? _ref[0] : void 0;
_ref1 = _this.parameters;
for (name in _ref1) {
param = _ref1[name];
last = (_ref1 = recordsets.pop()) != null ? _ref1[0] : void 0;
_ref2 = _this.parameters;
for (name in _ref2) {
param = _ref2[name];
if (!(param.io === 2)) {

@@ -562,3 +519,3 @@ continue;

MsnodesqlRequest.prototype.execute = function(procedure, callback) {
var cmd, name, param, spp, started, _ref;
var cmd, name, param, spp, started, _ref1;
if (this.verbose) {

@@ -569,9 +526,9 @@ console.log("---------- sql execute --------\n proc: " + procedure);

cmd = "declare " + (['@___return___ int'].concat((function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
for (name in _ref1) {
param = _ref1[name];
if (param.io === 2) {
_results.push("@" + param.name + " " + (typeDeclaration(param.type, param)));
_results.push("@" + param.name + " " + (declare(param.type, param)));
}

@@ -583,11 +540,11 @@ }

spp = [];
_ref = this.parameters;
for (name in _ref) {
param = _ref[name];
_ref1 = this.parameters;
for (name in _ref1) {
param = _ref1[name];
if (this.verbose) {
console.log(" " + (param.io === 1 ? " input" : "output") + ": @" + param.name + ", " + param.type.declaration + ", " + param.value);
}
if (param.io === 2) {
spp.push("@" + param.name + "=@" + param.name + " output");
} else {
if (this.verbose) {
console.log(" input: @" + param.name + ", " + param.type.declaration + ", " + param.value);
}
spp.push("@" + param.name + "=?");

@@ -598,7 +555,7 @@ }

cmd += "select " + (['@___return___ as \'___return___\''].concat((function() {
var _ref1, _results;
_ref1 = this.parameters;
var _ref2, _results;
_ref2 = this.parameters;
_results = [];
for (name in _ref1) {
param = _ref1[name];
for (name in _ref2) {
param = _ref2[name];
if (param.io === 2) {

@@ -616,3 +573,3 @@ _results.push("@" + param.name + " as '" + param.name + "'");

return function(err, recordsets) {
var elapsed, last, returnValue, _ref1, _ref2;
var elapsed, last, returnValue, _ref2, _ref3;
_this.nested = false;

@@ -628,8 +585,8 @@ if (err) {

} else {
last = (_ref1 = recordsets.pop()) != null ? _ref1[0] : void 0;
last = (_ref2 = recordsets.pop()) != null ? _ref2[0] : void 0;
if (last && (last.___return___ != null)) {
returnValue = last.___return___;
_ref2 = _this.parameters;
for (name in _ref2) {
param = _ref2[name];
_ref3 = _this.parameters;
for (name in _ref3) {
param = _ref3[name];
if (!(param.io === 2)) {

@@ -636,0 +593,0 @@ continue;

@@ -14,6 +14,23 @@ // Generated by CoffeeScript 1.7.1

require('tds/lib/tds-constants.js').TdsConstants.dataTypesByName.GUIDTYPE.sqlType = 'UniqueIdentifier';
require('tds').Connection.prototype.setAutoCommit = function(autoCommit, autoCommitCallback) {
if (this._autoCommit === autoCommit) {
return autoCommitCallback(); // <- fix here
} else {
if (this._currentStatement != null) {
throw new Error('Cannot change auto commit while statement is executing');
}
this._pendingCallback = autoCommitCallback;
this._currentStatement = '#setAutoCommit';
if (autoCommit) {
return this._client.sqlBatch('SET IMPLICIT_TRANSACTIONS OFF');
} else {
return this._client.sqlBatch('SET IMPLICIT_TRANSACTIONS ON');
}
}
};;
} catch (_error) {
ex = _error;
console.log(ex);
}
}).call(this);
// Generated by CoffeeScript 1.7.1
(function() {
var FIXED, ISOLATION_LEVEL, Pool, TYPES, castParameter, createColumns, createParameterHeader, formatHex, isolationLevelDeclaration, parseGuid, tds, typeDeclaration, util,
var FIXED, ISOLATION_LEVEL, Pool, TYPES, castParameter, createColumns, createParameterHeader, declare, formatHex, isolationLevelDeclaration, parseGuid, tds, util, _ref,
__hasProp = {}.hasOwnProperty,

@@ -15,3 +15,3 @@ __extends = 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; };

TYPES = require('./datatypes').TYPES;
_ref = require('./datatypes'), TYPES = _ref.TYPES, declare = _ref.declare;

@@ -94,5 +94,5 @@ ISOLATION_LEVEL = require('./isolationlevel');

createParameterHeader = function(param) {
var header, _ref, _ref1, _ref2;
var header, _ref1, _ref2, _ref3;
header = {
type: param.type.name
type: param.type.declaration
};

@@ -108,3 +108,3 @@ switch (param.type) {

case TYPES.Binary:
header.size = (_ref = (_ref1 = param.length) != null ? _ref1 : (_ref2 = param.value) != null ? _ref2.length : void 0) != null ? _ref : 1;
header.size = (_ref1 = (_ref2 = param.length) != null ? _ref2 : (_ref3 = param.value) != null ? _ref3.length : void 0) != null ? _ref1 : 1;
}

@@ -138,27 +138,2 @@ return header;

typeDeclaration = function(type, options) {
var _ref, _ref1;
switch (type) {
case TYPES.VarChar:
case TYPES.NVarChar:
case TYPES.VarBinary:
return "" + type.declaration + " (MAX)";
case TYPES.Char:
case TYPES.NChar:
case TYPES.Binary:
return "" + type.declaration + " (" + ((_ref = options.length) != null ? _ref : 1) + ")";
case TYPES.Time:
case TYPES.DateTime2:
case TYPES.DateTimeOffset:
return "" + type.declaration + " (" + ((_ref1 = options.scale) != null ? _ref1 : 7) + ")";
default:
return type.declaration;
}
};
/*
@ignore
*/
isolationLevelDeclaration = function(type) {

@@ -227,3 +202,3 @@ switch (type) {

TDSConnection.prototype.connect = function(config, callback) {
var cfg, cfg_pool, key, value, _ref;
var cfg, cfg_pool, key, value, _ref1;
cfg = {

@@ -243,3 +218,3 @@ userName: config.user,

return function(callback) {
var c, timeouted, tmr, _ref;
var c, timeouted, tmr, _ref1;
c = new tds.Connection(cfg);

@@ -251,3 +226,3 @@ timeouted = false;

return callback(new ConnectionError("Connection timeout.", null));
}, (_ref = config.timeout) != null ? _ref : 15000);
}, (_ref1 = config.timeout) != null ? _ref1 : 15000);
return c.connect(function(err) {

@@ -276,5 +251,5 @@ clearTimeout(tmr);

if (config.pool) {
_ref = config.pool;
for (key in _ref) {
value = _ref[key];
_ref1 = config.pool;
for (key in _ref1) {
value = _ref1[key];
cfg_pool[key] = value;

@@ -371,22 +346,4 @@ }

TDSRequest.prototype.connection = null;
TDSRequest.prototype._acquire = function(callback) {
if (this.transaction) {
return this.transaction.queue(callback);
} else {
return this.connection.pool.acquire(callback);
}
};
TDSRequest.prototype._release = function(connection) {
if (this.transaction) {
return this.transaction.next();
} else {
return this.connection.pool.release(connection);
}
};
TDSRequest.prototype.query = function(command, callback) {
var columns, error, handleOutput, input, name, output, param, paramHeaders, paramValues, recordset, recordsets, started, _ref;
var columns, error, handleOutput, input, name, output, param, paramHeaders, paramValues, recordset, recordsets, started, _ref1;
if (this.verbose && !this.nested) {

@@ -415,5 +372,5 @@ console.log("---------- sql query ----------\n query: " + command);

paramValues = {};
_ref = this.parameters;
for (name in _ref) {
param = _ref[name];
_ref1 = this.parameters;
for (name in _ref1) {
param = _ref1[name];
if (!(param.io === 1)) {

@@ -427,9 +384,9 @@ continue;

input = (function() {
var _ref1, _results;
_ref1 = this.parameters;
var _ref2, _results;
_ref2 = this.parameters;
_results = [];
for (name in _ref1) {
param = _ref1[name];
for (name in _ref2) {
param = _ref2[name];
if (param.io === 2) {
_results.push("@" + param.name + " " + (typeDeclaration(param.type, param)));
_results.push("@" + param.name + " " + (declare(param.type, param)));
}

@@ -440,7 +397,7 @@ }

output = (function() {
var _ref1, _results;
_ref1 = this.parameters;
var _ref2, _results;
_ref2 = this.parameters;
_results = [];
for (name in _ref1) {
param = _ref1[name];
for (name in _ref2) {
param = _ref2[name];
if (param.io === 2) {

@@ -466,7 +423,7 @@ _results.push("@" + param.name + " as '" + param.name + "'");

req.on('row', function(tdsrow) {
var col, exi, row, value, _i, _len, _ref1;
var col, exi, row, value, _i, _len, _ref2;
row = {};
_ref1 = tdsrow.metadata.columns;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
col = _ref1[_i];
_ref2 = tdsrow.metadata.columns;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
col = _ref2[_i];
value = tdsrow.getValue(col.name);

@@ -511,3 +468,3 @@ if (value != null) {

req.on('done', function(res) {
var elapsed, last, _ref1, _ref2;
var elapsed, last, _ref2, _ref3;
if (!_this.nested) {

@@ -518,6 +475,6 @@ if (recordset) {

if (handleOutput) {
last = (_ref1 = recordsets.pop()) != null ? _ref1[0] : void 0;
_ref2 = _this.parameters;
for (name in _ref2) {
param = _ref2[name];
last = (_ref2 = recordsets.pop()) != null ? _ref2[0] : void 0;
_ref3 = _this.parameters;
for (name in _ref3) {
param = _ref3[name];
if (!(param.io === 2)) {

@@ -559,3 +516,3 @@ continue;

TDSRequest.prototype.execute = function(procedure, callback) {
var cmd, name, param, spp, started, _ref;
var cmd, name, param, spp, started, _ref1;
if (this.verbose) {

@@ -566,9 +523,9 @@ console.log("---------- sql execute --------\n proc: " + procedure);

cmd = "declare " + (['@___return___ int'].concat((function() {
var _ref, _results;
_ref = this.parameters;
var _ref1, _results;
_ref1 = this.parameters;
_results = [];
for (name in _ref) {
param = _ref[name];
for (name in _ref1) {
param = _ref1[name];
if (param.io === 2) {
_results.push("@" + param.name + " " + (typeDeclaration(param.type, param)));
_results.push("@" + param.name + " " + (declare(param.type, param)));
}

@@ -580,11 +537,11 @@ }

spp = [];
_ref = this.parameters;
for (name in _ref) {
param = _ref[name];
_ref1 = this.parameters;
for (name in _ref1) {
param = _ref1[name];
if (this.verbose) {
console.log(" " + (param.io === 1 ? " input" : "output") + ": @" + param.name + ", " + param.type.declaration + ", " + param.value);
}
if (param.io === 2) {
spp.push("@" + param.name + "=@" + param.name + " output");
} else {
if (this.verbose) {
console.log(" input: @" + param.name + ", " + param.type.declaration + ", " + param.value);
}
spp.push("@" + param.name + "=@" + param.name);

@@ -595,7 +552,7 @@ }

cmd += "select " + (['@___return___ as \'___return___\''].concat((function() {
var _ref1, _results;
_ref1 = this.parameters;
var _ref2, _results;
_ref2 = this.parameters;
_results = [];
for (name in _ref1) {
param = _ref1[name];
for (name in _ref2) {
param = _ref2[name];
if (param.io === 2) {

@@ -613,3 +570,3 @@ _results.push("@" + param.name + " as '" + param.name + "'");

return function(err, recordsets) {
var elapsed, last, returnValue, _ref1, _ref2;
var elapsed, last, returnValue, _ref2, _ref3;
_this.nested = false;

@@ -625,8 +582,8 @@ if (err) {

} else {
last = (_ref1 = recordsets.pop()) != null ? _ref1[0] : void 0;
last = (_ref2 = recordsets.pop()) != null ? _ref2[0] : void 0;
if (last && (last.___return___ != null)) {
returnValue = last.___return___;
_ref2 = _this.parameters;
for (name in _ref2) {
param = _ref2[name];
_ref3 = _this.parameters;
for (name in _ref3) {
param = _ref3[name];
if (!(param.io === 2)) {

@@ -633,0 +590,0 @@ continue;

@@ -411,19 +411,3 @@ // Generated by CoffeeScript 1.7.1

TediousRequest.prototype._acquire = function(callback) {
if (this.transaction) {
return this.transaction.queue(callback);
} else {
return this.connection.pool.acquire(callback);
}
};
TediousRequest.prototype._release = function(connection) {
if (this.transaction) {
return this.transaction.next();
} else {
return this.connection.pool.release(connection);
}
};
/*

@@ -605,3 +589,3 @@ Execute specified sql command.

return function(err, connection) {
var name, param, req, _ref, _ref1;
var name, param, req, _ref;
if (!err) {

@@ -717,22 +701,16 @@ if (_this.verbose) {

param = _ref[name];
if (!(param.io === 1)) {
continue;
}
if (_this.verbose) {
if (param.value === tds.TYPES.Null) {
console.log(" input: @" + param.name + ", null");
console.log(" " + (param.io === 1 ? " input" : "output") + ": @" + param.name + ", null");
} else {
console.log(" input: @" + param.name + ", " + (param.type.declaration.toLowerCase()) + ", " + param.value);
console.log(" " + (param.io === 1 ? " input" : "output") + ": @" + param.name + ", " + (param.type.declaration.toLowerCase()) + ", " + param.value);
}
}
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), {
length: param.length,
scale: param.scale,
precision: param.precision
});
}
_ref1 = _this.parameters;
for (name in _ref1) {
param = _ref1[name];
if (param.io === 2) {
if (param.io === 1) {
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), {
length: param.length,
scale: param.scale,
precision: param.precision
});
} else {
req.addOutputParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), {

@@ -739,0 +717,0 @@ length: param.length,

@@ -17,5 +17,6 @@ {

"tedious",
"node-sqlserver"
"node-sqlserver",
"sqlserver"
],
"version": "0.5.1",
"version": "0.5.2",
"main": "index.js",

@@ -22,0 +23,0 @@ "repository": {

@@ -11,3 +11,3 @@ # node-mssql [![Dependency Status](https://david-dm.org/patriksimek/node-mssql.png)](https://david-dm.org/patriksimek/node-mssql) [![NPM version](https://badge.fury.io/js/mssql.png)](http://badge.fury.io/js/mssql)

- Unified interface for multiple MSSQL modules
- Connection pooling with Transactions support
- Connection pooling with Transactions and Prepared statements
- Parametrized Stored Procedures in [node-tds](https://github.com/cretz/node-tds) and [Microsoft Driver for Node.js for SQL Server](https://github.com/WindowsAzure/node-sqlserver)

@@ -22,5 +22,11 @@ - Serialization of Geography and Geometry CLR types

## What's new in 0.5.1 (stable, npm)
## What's new in 0.5.2 (stable, npm)
- Updated to new Tedious 0.2.1
- Support for [Prepared Statements](#prepared-statement)
- Fixed order of output parameters
- Minor fixes in node-tds driver
## What's new in 0.5.1
- Updated to new Tedious 0.2.2
- Added support for TDS 7.4

@@ -151,6 +157,15 @@ - Added request cancelation

### Prepared Statements
* [PreparedStatement](#prepared-statement)
* [input](#prepared-statement-input)
* [output](#prepared-statement-output)
* [prepare](#prepare)
* [execute](#prepared-statement-execute)
* [unprepare](#unprepare)
### Other
* [Geography and Geometry](#geography)
* [Table-Value Parameter](#tvp)
* [Table-Valued Parameter](#tvp)
* [Errors](#errors)

@@ -507,3 +522,3 @@ * [Metadata](#meta)

transaction.begin(function(err) {
// ...
// ... error checks
});

@@ -528,6 +543,6 @@ ```

transaction.begin(function(err) {
// ...
// ... error checks
transaction.commit(function(err) {
//...
// ... error checks
})

@@ -553,6 +568,6 @@ });

transaction.begin(function(err) {
// ...
// ... error checks
transaction.rollback(function(err) {
//...
// ... error checks
})

@@ -562,2 +577,151 @@ });

<a name="prepared-statement" />
## PreparedStatement
**Important:** always use `PreparedStatement` class to create prepared statements - it ensures that all your executions of prepared statement are executed on one connection. Once you call `prepare`, a single connection is aquired from the connection pool and all subsequent executions are executed exclusively on this connection. Prepared Statement also contains queue to make sure your executions are executed in series. After you call `unprepare`, connection is then released back to the connection pool.
```javascript
var ps = new sql.PreparedStatement(/* [connection] */);
```
If you ommit connection argument, global connection is used instead.
__Example__
```javascript
var ps = new sql.PreparedStatement(/* [connection] */);
ps.input('param', sql.Int);
ps.prepare('select @param as value', function(err, recordsets) {
// ... error checks
ps.execute({param: 12345}, function(err, recordset) {
// ... error checks
ps.unprepare(function(err) {
// ... error checks
});
});
});
```
**IMPORTANT**: Rememeber that each prepared statement means one reserved connection from the pool. Don't forget to unprepare a prepared statement!
**TIP**: You can also create prepared statements in transactions (`new sql.PreparedStatement(transaction)`), but keep in mind you can't execute other requests in the transaction until you call `unprepare`.
---------------------------------------
<a name="prepared-statement-input" />
### input(name, [type], value)
Add an input parameter to the prepared statement.
__Arguments__
- **name** - Name of the input parameter without @ char.
- **type** - SQL data type of input parameter.
__Example__
```javascript
ps.input('input_parameter', sql.Int);
ps.input('input_parameter', sql.VarChar(50));
```
---------------------------------------
<a name="prepared-statement-output" />
### output(name, type, [value])
Add an output parameter to the prepared statement.
__Arguments__
- **name** - Name of the output parameter without @ char.
- **type** - SQL data type of output parameter.
__Example__
```javascript
ps.output('output_parameter', sql.Int);
ps.output('output_parameter', sql.VarChar(50));
```
---------------------------------------
<a name="prepare" />
### prepare(statement, [callback])
Prepare a statement.
__Arguments__
- **statement** - T-SQL statement to prepare.
- **callback(err)** - A callback which is called after preparation has completed, or an error has occurred. Optional.
__Example__
```javascript
var ps = new sql.PreparedStatement();
ps.prepare('select @param as value', function(err) {
// ... error checks
});
```
---------------------------------------
<a name="prepared-statement-execute" />
### execute(values, [callback])
Execute a prepared statement.
__Arguments__
- **values** - An object whose names correspond to the names of parameters that were added to the prepared statement before it was prepared.
- **callback(err)** - A callback which is called after execution has completed, or an error has occurred. Optional.
__Example__
```javascript
var ps = new sql.PreparedStatement();
ps.input('param', sql.Int);
ps.prepare('select @param as value', function(err) {
// ... error checks
ps.execute({param: 12345}, function(err, recordset) {
// ... error checks
})
});
```
---------------------------------------
<a name="unprepare" />
### unprepare([callback])
Unprepare a prepared statement.
__Arguments__
- **callback(err)** - A callback which is called after unpreparation has completed, or an error has occurred. Optional.
__Example__
```javascript
var ps = new sql.PreparedStatement();
ps.input('param', sql.Int);
ps.prepare('select @param as value', function(err, recordsets) {
// ... error checks
ps.execute({param: 12345}, function(err, recordset) {
// ... error checks
ps.unprepare(function(err) {
// ... error checks
});
});
});
```
<a name="geography" />

@@ -595,3 +759,3 @@ ## Geography and Geometry

<a name="tvp" />
## Table-Value Parameter (TVP)
## Table-Valued Parameter (TVP)

@@ -645,2 +809,3 @@ Supported on SQL Server 2008 and later. Not supported by optional drivers `msnodesql` and `tds`. You can pass a data table as a parameter to stored procedure. First, we have to create custom type in our database.

- **RequestError** - Errors related to queries and stored procedures execution.
- **PreparedStatementError** - Errors related to prepared statements.

@@ -784,2 +949,3 @@ Those errors are initialized in node-mssql module and it's stack can be cropped. You can always access original error with `err.originalError`.

- node-tds 0.1.0 doesn't support Binary, VarBinary and Image as parameters.
- node-tds 0.1.0 always return date/time values in local time.

@@ -786,0 +952,0 @@ <a name="license" />

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc