Gathering detailed insights and metrics for mssql-tedious-int64
Gathering detailed insights and metrics for mssql-tedious-int64
Gathering detailed insights and metrics for mssql-tedious-int64
Gathering detailed insights and metrics for mssql-tedious-int64
npm install mssql-tedious-int64
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (97.51%)
TSQL (2.49%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,263 Stars
1,383 Commits
469 Forks
89 Watchers
5 Branches
96 Contributors
Updated on Jul 02, 2025
Latest Version
2.1.6
Package Id
mssql-tedious-int64@2.1.6
Size
55.35 kB
NPM Version
2.7.4
Node Version
0.12.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
2
An easy-to-use MSSQL database connector for Node.js / io.js.
Why do you want to use node-mssql?
There is also co wrapper available - co-mssql.
If you're looking for session store for connect/express, visit connect-mssql.
Supported TDS drivers:
node-mssql uses Tedious as the default driver.
npm install mssql
1var sql = require('mssql'); 2 3var config = { 4 user: '...', 5 password: '...', 6 server: 'localhost', // You can use 'localhost\\instance' to connect to named instance 7 database: '...', 8 9 options: { 10 encrypt: true // Use this if you're on Windows Azure 11 } 12} 13 14var connection = new sql.Connection(config, function(err) { 15 // ... error checks 16 17 // Query 18 19 var request = new sql.Request(connection); // or: var request = connection.request(); 20 request.query('select 1 as number', function(err, recordset) { 21 // ... error checks 22 23 console.dir(recordset); 24 }); 25 26 // Stored Procedure 27 28 var request = new sql.Request(connection); 29 request.input('input_parameter', sql.Int, 10); 30 request.output('output_parameter', sql.VarChar(50)); 31 request.execute('procedure_name', function(err, recordsets, returnValue) { 32 // ... error checks 33 34 console.dir(recordsets); 35 }); 36 37});
### Streaming example with one global connection1var sql = require('mssql'); 2 3var config = { 4 user: '...', 5 password: '...', 6 server: 'localhost', // You can use 'localhost\\instance' to connect to named instance 7 database: '...', 8 9 options: { 10 encrypt: true // Use this if you're on Windows Azure 11 } 12} 13 14sql.connect(config, function(err) { 15 // ... error checks 16 17 // Query 18 19 var request = new sql.Request(); 20 request.query('select 1 as number', function(err, recordset) { 21 // ... error checks 22 23 console.dir(recordset); 24 }); 25 26 // Stored Procedure 27 28 var request = new sql.Request(); 29 request.input('input_parameter', sql.Int, value); 30 request.output('output_parameter', sql.VarChar(50)); 31 request.execute('procedure_name', function(err, recordsets, returnValue) { 32 // ... error checks 33 34 console.dir(recordsets); 35 }); 36 37});
If you plan to work with large amount of rows, you should always use streaming. Once you enable this, you must listen for events to receive data.
1var sql = require('mssql'); 2 3var config = { 4 user: '...', 5 password: '...', 6 server: 'localhost', // You can use 'localhost\\instance' to connect to named instance 7 database: '...', 8 stream: true, // You can enable streaming globally 9 10 options: { 11 encrypt: true // Use this if you're on Windows Azure 12 } 13} 14 15sql.connect(config, function(err) { 16 // ... error checks 17 18 var request = new sql.Request(); 19 request.stream = true; // You can set streaming differently for each request 20 request.query('select * from verylargetable'); // or request.execute(procedure); 21 22 request.on('recordset', function(columns) { 23 // Emitted once for each recordset in a query 24 }); 25 26 request.on('row', function(row) { 27 // Emitted for each row in a recordset 28 }); 29 30 request.on('error', function(err) { 31 // May be emitted multiple times 32 }); 33 34 request.on('done', function(returnValue) { 35 // Always emitted as the last one 36 }); 37});
### Basic configuration is same for all drivers.1var config = { 2 user: '...', 3 password: '...', 4 server: 'localhost', 5 database: '...', 6 pool: { 7 max: 10, 8 min: 0, 9 idleTimeoutMillis: 30000 10 } 11}
tedious
). Possible values: tedious
, msnodesql
or tds
.1433
). Don't set when connecting to named instance.15000
).15000
).false
). You can also enable streaming for each request independently (request.stream = true
). Always set to true
if you plan to work with large amount of rows.10
).0
).30000
).true
).false
) Encryption support is experimental.7_4
, available: 7_1
, 7_2
, 7_3_A
, 7_3_B
, 7_4
).XACT_ABORT
during the initial SQL phase of a connection.More information about Tedious specific options: http://pekim.github.io/tedious/api-connection.html
### Microsoft Driver for Node.js for SQL ServerThis driver is not part of the default package and must be installed separately by npm install msnodesql
. If you are looking for compiled binaries, see node-sqlserver-binary.
false
).true
).Default connection string when connecting to port:
Driver={SQL Server Native Client 11.0};Server={#{server},#{port}};Database={#{database}};Uid={#{user}};Pwd={#{password}};Trusted_Connection={#{trusted}};
Default connection string when connecting to named instance:
Driver={SQL Server Native Client 11.0};Server={#{server}\\#{instance}};Database={#{database}};Uid={#{user}};Pwd={#{password}};Trusted_Connection={#{trusted}};
### node-tds
This driver is not part of the default package and must be installed separately by npm install tds
.
This module updates the node-tds driver with extra features and bug fixes by overriding some of its internal functions. If you want to disable this, require module with var sql = require('mssql/nofix')
.
1var connection = new sql.Connection({ /* config */ });
Errors
ConnectionError
) - Unknown driver.close
).Create connection to the server.
Arguments
Example
1var connection = new sql.Connection({ 2 user: '...', 3 password: '...', 4 server: 'localhost', 5 database: '...' 6}); 7 8connection.connect(function(err) { 9 // ... 10});
Errors
ConnectionError
) - Login failed.ConnectionError
) - Connection timeout.ConnectionError
) - Database is already connected!ConnectionError
) - Already connecting to database!ConnectionError
) - Instance lookup failed.ConnectionError
) - Socket error.Close connection to the server.
Example
## Requests1connection.close();
1var request = new sql.Request(/* [connection] */);
If you omit connection argument, global connection is used instead.
Call a stored procedure.
Arguments
returnValue
is also accessible as property of recordsets. Optional. If omited, returns Promise.Example
1var request = new sql.Request(); 2request.input('input_parameter', sql.Int, value); 3request.output('output_parameter', sql.Int); 4request.execute('procedure_name', function(err, recordsets, returnValue) { 5 // ... error checks 6 7 console.log(recordsets.length); // count of recordsets returned by the procedure 8 console.log(recordsets[0].length); // count of rows contained in first recordset 9 console.log(returnValue); // procedure return value 10 console.log(recordsets.returnValue); // same as previous line 11 12 console.log(request.parameters.output_parameter.value); // output value 13 14 // ... 15});
Errors
RequestError
) - Message from SQL ServerRequestError
) - Canceled.RequestError
) - Request timeout.RequestError
) - No connection is specified for that request.ConnectionError
) - Connection not yet open.ConnectionError
) - Connection is closed.TransactionError
) - Transaction has not begun.TransactionError
) - Transaction was aborted (by user or because of an error).Add an input parameter to the request.
Arguments
undefined
ans NaN
values are automatically converted to null
values.Example
1request.input('input_parameter', value); 2request.input('input_parameter', sql.Int, value);
JS Data Type To SQL Data Type Map
String
-> sql.NVarChar
Number
-> sql.Int
Boolean
-> sql.Bit
Date
-> sql.DateTime
Buffer
-> sql.VarBinary
sql.Table
-> sql.TVP
Default data type for unknown object is sql.NVarChar
.
You can define your own type map.
1sql.map.register(MyClass, sql.Text);
You can also overwrite the default type map.
1sql.map.register(Number, sql.BigInt);
Errors (synchronous)
RequestError
) - Invalid number of arguments.RequestError
) - SQL injection warning.Add an output parameter to the request.
Arguments
undefined
and NaN
values are automatically converted to null
values. Optional.Example
1request.output('output_parameter', sql.Int); 2request.output('output_parameter', sql.VarChar(50), 'abc');
Errors (synchronous)
RequestError
) - Invalid number of arguments.RequestError
) - SQL injection warning.Sets request to stream
mode and pulls all rows from all recordsets to a given stream.
Arguments
Example
1var request = new sql.Request(); 2request.pipe(stream); 3request.query('select * from mytable'); 4stream.on('error', function(err) { 5 // ... 6}); 7stream.on('finish', function() { 8 // ... 9});
Version
2.0
Execute the SQL command. To execute commands like create procedure
or if you plan to work with local temporary tables, use batch instead.
Arguments
Example
1var request = new sql.Request(); 2request.query('select 1 as number', function(err, recordset) { 3 // ... error checks 4 5 console.log(recordset[0].number); // return 1 6 7 // ... 8});
Errors
RequestError
) - Request timeout.RequestError
) - Message from SQL ServerRequestError
) - Canceled.RequestError
) - No connection is specified for that request.ConnectionError
) - Connection not yet open.ConnectionError
) - Connection is closed.TransactionError
) - Transaction has not begun.TransactionError
) - Transaction was aborted (by user or because of an error).You can enable multiple recordsets in queries with the request.multiple = true
command.
1var request = new sql.Request(); 2request.multiple = true; 3 4request.query('select 1 as number; select 2 as number', function(err, recordsets) { 5 // ... error checks 6 7 console.log(recordsets[0][0].number); // return 1 8 console.log(recordsets[1][0].number); // return 2 9});
Execute the SQL command. Unlike query, it doesn't use sp_executesql
, so is not likely that SQL Server will reuse the execution plan it generates for the SQL. Use this only in special cases, for example when you need to execute commands like create procedure
which can't be executed with query or if you're executing statements longer than 4000 chars on SQL Server 2000. Also you should use this if you're plan to work with local temporary tables (more information here).
NOTE: Table-Valued Parameter (TVP) is not supported in batch.
Arguments
Example
1var request = new sql.Request(); 2request.batch('create procedure #temporary as select * from table', function(err, recordset) { 3 // ... error checks 4});
Errors
RequestError
) - Request timeout.RequestError
) - Message from SQL ServerRequestError
) - Canceled.RequestError
) - No connection is specified for that request.ConnectionError
) - Connection not yet open.ConnectionError
) - Connection is closed.TransactionError
) - Transaction has not begun.TransactionError
) - Transaction was aborted (by user or because of an error).You can enable multiple recordsets in queries with the request.multiple = true
command.
Perform a bulk insert.
Arguments
sql.Table
instance.Example
1var table = new sql.Table('table_name'); // or temporary table, e.g. #temptable 2table.create = true; 3table.columns.add('a', sql.Int, {nullable: true}); 4table.columns.add('b', sql.VarChar(50), {nullable: false}); 5table.rows.add(777, 'test'); 6 7var request = new sql.Request(); 8request.bulk(table, function(err, rowCount) { 9 // ... error checks 10});
IMPORTANT: Always indicate whether the column is nullable or not!
TIP: If you set table.create
to true
, module will check if the table exists before it start sending data. If it doesn't, it will automatically create it.
TIP: You can also create Table variable from any recordset with recordset.toTable()
.
Errors
RequestError
) - Table name must be specified for bulk insert.RequestError
) - Request timeout.RequestError
) - Message from SQL ServerRequestError
) - Canceled.RequestError
) - No connection is specified for that request.ConnectionError
) - Connection not yet open.ConnectionError
) - Connection is closed.TransactionError
) - Transaction has not begun.TransactionError
) - Transaction was aborted (by user or because of an error).Cancel currently executing request. Return true
if cancellation packet was send successfully.
Example
## Transactions1var request = new sql.Request(); 2request.query('waitfor delay \'00:00:05\'; select 1 as number', function(err, recordset) { 3 console.log(err instanceof sql.RequestError); // true 4 console.log(err.message); // Canceled. 5 console.log(err.code); // ECANCEL 6 7 // ... 8}); 9 10request.cancel();
IMPORTANT: always use Transaction
class to create transactions - it ensures that all your requests are executed on one connection. Once you call begin
, a single connection is acquired from the connection pool and all subsequent requests (initialized with the Transaction
object) are executed exclusively on this connection. Transaction also contains a queue to make sure your requests are executed in series. After you call commit
or rollback
, connection is then released back to the connection pool.
1var transaction = new sql.Transaction(/* [connection] */);
If you omit connection argument, global connection is used instead.
Example
1var transaction = new sql.Transaction(/* [connection] */); 2transaction.begin(function(err) { 3 // ... error checks 4 5 var request = new sql.Request(transaction); 6 request.query('insert into mytable (mycolumn) values (12345)', function(err, recordset) { 7 // ... error checks 8 9 transaction.commit(function(err, recordset) { 10 // ... error checks 11 12 console.log("Transaction commited."); 13 }); 14 }); 15});
Transaction can also be created by var transaction = connection.transaction();
. Requests can also be created by var request = transaction.request();
.
Aborted transactions
This example shows how you should correctly handle transaction errors when abortTransactionOnError
(XACT_ABORT
) is enabled. Added in 2.0.
1var transaction = new sql.Transaction(/* [connection] */); 2transaction.begin(function(err) { 3 // ... error checks 4 5 var rolledBack = false; 6 7 transaction.on('rollback', function(aborted) { 8 // emited with aborted === true 9 10 rolledBack = true; 11 }); 12 13 var request = new sql.Request(transaction); 14 request.query('insert into mytable (bitcolumn) values (2)', function(err, recordset) { 15 // insert should fail because of invalid value 16 17 if (err) { 18 if (!rolledBack) { 19 transaction.rollback(function(err) { 20 // ... error checks 21 }); 22 } 23 } else { 24 transaction.commit(function(err) { 25 // ... error checks 26 }); 27 } 28 }); 29});
Begin a transaction.
Arguments
READ_COMMITTED
by default. For possible values see sql.ISOLATION_LEVEL
.Example
1var transaction = new sql.Transaction(); 2transaction.begin(function(err) { 3 // ... error checks 4});
Errors
ConnectionError
) - Connection not yet open.TransactionError
) - Transaction has already begun.Commit a transaction.
Arguments
Example
1var transaction = new sql.Transaction(); 2transaction.begin(function(err) { 3 // ... error checks 4 5 transaction.commit(function(err) { 6 // ... error checks 7 }) 8});
Errors
TransactionError
) - Transaction has not begun.TransactionError
) - Can't commit transaction. There is a request in progress.Rollback a transaction. If the queue isn't empty, all queued requests will be canceled and the transaction will be marked as aborted.
Arguments
Example
1var transaction = new sql.Transaction(); 2transaction.begin(function(err) { 3 // ... error checks 4 5 transaction.rollback(function(err) { 6 // ... error checks 7 }) 8});
Errors
TransactionError
) - Transaction has not begun.TransactionError
) - Can't rollback transaction. There is a request in progress.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 a queue to make sure your executions are executed in series. After you call unprepare
, the connection is then released back to the connection pool.
1var ps = new sql.PreparedStatement(/* [connection] */);
If you omit the connection argument, the global connection is used instead.
Example
1var ps = new sql.PreparedStatement(/* [connection] */); 2ps.input('param', sql.Int); 3ps.prepare('select @param as value', function(err) { 4 // ... error checks 5 6 ps.execute({param: 12345}, function(err, recordset) { 7 // ... error checks 8 9 ps.unprepare(function(err) { 10 // ... error checks 11 12 }); 13 }); 14});
IMPORTANT: Remember 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
.
Add an input parameter to the prepared statement.
Arguments
Example
1ps.input('input_parameter', sql.Int); 2ps.input('input_parameter', sql.VarChar(50));
Errors (synchronous)
PreparedStatementError
) - Invalid number of arguments.PreparedStatementError
) - SQL injection warning.Add an output parameter to the prepared statement.
Arguments
Example
1ps.output('output_parameter', sql.Int); 2ps.output('output_parameter', sql.VarChar(50));
Errors (synchronous)
PreparedStatementError
) - Invalid number of arguments.PreparedStatementError
) - SQL injection warning.Prepare a statement.
Arguments
Example
1var ps = new sql.PreparedStatement(); 2ps.prepare('select @param as value', function(err) { 3 // ... error checks 4});
Errors
ConnectionError
) - Connection not yet open.PreparedStatementError
) - Statement is already prepared.TransactionError
) - Transaction has not begun.Execute a prepared statement.
Arguments
Example
1var ps = new sql.PreparedStatement(); 2ps.input('param', sql.Int); 3ps.prepare('select @param as value', function(err) { 4 // ... error checks 5 6 ps.execute({param: 12345}, function(err, recordset) { 7 // ... error checks 8 9 console.log(recordset[0].value); // return 12345 10 }); 11});
You can enable multiple recordsets by ps.multiple = true
command.
1var ps = new sql.PreparedStatement(); 2ps.input('param', sql.Int); 3ps.prepare('select @param as value', function(err) { 4 // ... error checks 5 6 ps.multiple = true; 7 ps.execute({param: 12345}, function(err, recordsets) { 8 // ... error checks 9 10 console.log(recordsets[0][0].value); // return 12345 11 }); 12});
You can also stream executed request.
1var ps = new sql.PreparedStatement(); 2ps.input('param', sql.Int); 3ps.prepare('select @param as value', function(err) { 4 // ... error checks 5 6 ps.stream = true; 7 request = ps.execute({param: 12345}); 8 9 request.on('recordset', function(columns) { 10 // Emitted once for each recordset in a query 11 }); 12 13 request.on('row', function(row) { 14 // Emitted for each row in a recordset 15 }); 16 17 request.on('error', function(err) { 18 // May be emitted multiple times 19 }); 20 21 request.on('done', function(returnValue) { 22 // Always emitted as the last one 23 }); 24});
Errors
PreparedStatementError
) - Statement is not prepared.RequestError
) - Request timeout.RequestError
) - Message from SQL ServerRequestError
) - Canceled.Unprepare a prepared statement.
Arguments
Example
1var ps = new sql.PreparedStatement(); 2ps.input('param', sql.Int); 3ps.prepare('select @param as value', function(err, recordsets) { 4 // ... error checks 5 6 ps.unprepare(function(err) { 7 // ... error checks 8 9 }); 10});
Errors
PreparedStatementError
) - Statement is not prepared.Before you can start using CLI, you must install mssql
globally with npm install mssql -g
. Once you do that you will be able to execute mssql
command.
Setup
Create a .mssql.json
configuration file (anywhere). Structure of the file is the same as the standard configuration object.
1{ 2 "user": "...", 3 "password": "...", 4 "server": "localhost", 5 "database": "..." 6}
Example
1echo "select * from mytable" | mssql /path/to/config
Results in:
1[[{"username":"patriksimek","password":"tooeasy"}]]
You can also query for multiple recordsets.
1echo "select * from mytable; select * from myothertable" | mssql
Results in:
1[[{"username":"patriksimek","password":"tooeasy"}],[{"id":15,"name":"Product name"}]]
If you omit config path argument, mssql will try to load it from current working directory.
Version
2.0
## Geography and Geometrynode-mssql has built-in serializer for Geography and Geometry CLR data types.
1select geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656 )', 4326) 2select geometry::STGeomFromText('LINESTRING (100 100 10.3 12, 20 180, 180 180)', 0)
Results in:
## Table-Valued Parameter (TVP)1{ srid: 4326, 2 version: 1, 3 points: [ { x: 47.656, y: -122.36 }, { x: 47.656, y: -122.343 } ], 4 figures: [ { attribute: 1, pointOffset: 0 } ], 5 shapes: [ { parentOffset: -1, figureOffset: 0, type: 2 } ], 6 segments: [] } 7 8{ srid: 0, 9 version: 1, 10 points: 11 [ { x: 100, y: 100, z: 10.3, m: 12 }, 12 { x: 20, y: 180, z: NaN, m: NaN }, 13 { x: 180, y: 180, z: NaN, m: NaN } ], 14 figures: [ { attribute: 1, pointOffset: 0 } ], 15 shapes: [ { parentOffset: -1, figureOffset: 0, type: 2 } ], 16 segments: [] }
Supported on SQL Server 2008 and later. You can pass a data table as a parameter to stored procedure. First, we have to create custom type in our database.
1CREATE TYPE TestType AS TABLE ( a VARCHAR(50), b INT );
Next we will need a stored procedure.
1CREATE PROCEDURE MyCustomStoredProcedure (@tvp TestType readonly) AS SELECT * FROM @tvp
Now let's go back to our Node.js app.
1var tvp = new sql.Table() 2 3// Columns must correspond with type we have created in database. 4tvp.columns.add('a', sql.VarChar(50)); 5tvp.columns.add('b', sql.Int); 6 7// Add rows 8tvp.rows.add('hello tvp', 777); // Values are in same order as columns.
You can send table as a parameter to stored procedure.
1var request = new sql.Request(); 2request.input('tvp', tvp); 3request.execute('MyCustomStoredProcedure', function(err, recordsets, returnValue) { 4 // ... error checks 5 6 console.dir(recordsets[0][0]); // {a: 'hello tvp', b: 777} 7});
TIP: You can also create Table variable from any recordset with recordset.toTable()
.
You can retrieve a Promise when you omit a callback argument.
1var connection = new sql.Connection(config); 2connection.connect().then(function() { 3 var request = new sql.Request(connection); 4 request.query('select * from mytable').then(function(recordset) { 5 // ... 6 }).catch(function(err) { 7 // ... 8 }); 9}).catch(function(err) { 10 // ... 11});
Native Promise is returned by default. You can easily change this with sql.Promise = require('myownpromisepackage')
.
Version
2.0
## ErrorsThere are 4 types of errors you can handle:
Those errors are initialized in node-mssql module and its original stack may be cropped. You can always access original error with err.originalError
.
SQL Server may generate more than one error for one request so you can access preceding errors with err.precedingErrors
.
Each known error has code
property.
Type | Code | Description |
---|---|---|
ConnectionError | ELOGIN | Login failed. |
ConnectionError | ETIMEOUT | Connection timeout. |
ConnectionError | EDRIVER | Unknown driver. |
ConnectionError | EALREADYCONNECTED | Database is already connected! |
ConnectionError | EALREADYCONNECTING | Already connecting to database! |
ConnectionError | ENOTOPEN | Connection not yet open. |
ConnectionError | EINSTLOOKUP | Instance lookup failed. |
ConnectionError | ESOCKET | Scoket error. |
ConnectionError | ECONNCLOSED | Connection is closed. |
TransactionError | ENOTBEGUN | Transaction has not begun. |
TransactionError | EALREADYBEGUN | Transaction has already begun. |
TransactionError | EREQINPROG | Can't commit/rollback transaction. There is a request in progress. |
TransactionError | EABORT | Transaction has been aborted. |
RequestError | EREQUEST | Message from SQL Server. Error object contains additional details. |
RequestError | ECANCEL | Canceled. |
RequestError | ETIMEOUT | Request timeout. |
RequestError | EARGS | Invalid number of arguments. |
RequestError | EINJECT | SQL injection warning. |
RequestError | ENOCONN | No connection is specified for that request. |
PreparedStatementError | EARGS | Invalid number of arguments. |
PreparedStatementError | EINJECT | SQL injection warning. |
PreparedStatementError | EALREADYPREPARED | Statement is already prepared. |
PreparedStatementError | ENOTPREPARED | Statement is not prepared. |
SQL errors (RequestError
with err.code
equal to EREQUEST
) contains additional details.
Recordset metadata are accessible through the recordset.columns
property.
1var request = new sql.Request(); 2request.query('select convert(decimal(18, 4), 1) as first, \'asdf\' as second', function(err, recordset) { 3 console.dir(recordset.columns); 4 5 console.log(recordset.columns.first.type === sql.Decimal); // true 6 console.log(recordset.columns.second.type === sql.VarChar); // true 7});
Columns structure for example above:
## Data Types1{ first: { index: 0, name: 'first', length: 17, type: [sql.Decimal], scale: 4, precision: 18 }, 2 second: { index: 1, name: 'second', length: 4, type: [sql.VarChar] } }
You can define data types with length/precision/scale:
1request.input("name", sql.VarChar, "abc"); // varchar(3) 2request.input("name", sql.VarChar(50), "abc"); // varchar(50) 3request.input("name", sql.VarChar(sql.MAX), "abc"); // varchar(MAX) 4request.output("name", sql.VarChar); // varchar(8000) 5request.output("name", sql.VarChar, "abc"); // varchar(3) 6 7request.input("name", sql.Decimal, 155.33); // decimal(18, 0) 8request.input("name", sql.Decimal(10), 155.33); // decimal(10, 0) 9request.input("name", sql.Decimal(10, 2), 155.33); // decimal(10, 2) 10 11request.input("name", sql.DateTime2, new Date()); // datetime2(7) 12request.input("name", sql.DateTime2(5), new Date()); // datetime2(5)
List of supported data types:
sql.Bit
sql.BigInt
sql.Decimal ([precision], [scale])
sql.Float
sql.Int
sql.Money
sql.Numeric ([precision], [scale])
sql.SmallInt
sql.SmallMoney
sql.Real
sql.TinyInt
sql.Char ([length])
sql.NChar ([length])
sql.Text
sql.NText
sql.VarChar ([length])
sql.NVarChar ([length])
sql.Xml
sql.Time ([scale])
sql.Date
sql.DateTime
sql.DateTime2 ([scale])
sql.DateTimeOffset ([scale])
sql.SmallDateTime
sql.UniqueIdentifier
sql.Binary
sql.VarBinary ([length])
sql.Image
sql.UDT
sql.Geography
sql.Geometry
To setup MAX length for VarChar
, NVarChar
and VarBinary
use sql.MAX
length.
This module has built-in SQL injection protection. Always use parameters to pass sanitized values to your queries.
## Verbose Mode1var request = new sql.Request(); 2request.input('myval', sql.VarChar, '-- commented'); 3request.query('select @myval as myval', function(err, recordset) { 4 console.dir(recordset); 5});
You can enable verbose mode by request.verbose = true
command.
1var request = new sql.Request(); 2request.verbose = true; 3request.input('username', 'patriksimek'); 4request.input('password', 'dontuseplaintextpassword'); 5request.input('attempts', 2); 6request.execute('my_stored_procedure');
Output for the example above could look similar to this.
---------- sql execute --------
proc: my_stored_procedure
input: @username, varchar, patriksimek
input: @password, varchar, dontuseplaintextpassword
input: @attempts, bigint, 2
---------- response -----------
{ id: 1,
username: 'patriksimek',
password: 'dontuseplaintextpassword',
email: null,
language: 'en',
attempts: 2 }
---------- --------------------
return: 0
duration: 5ms
---------- completed ----------
## Known issues
config.options.tdsVersion = '7_1'
(issue)set language 'English';
.Copyright (c) 2013-2015 Patrik Simek
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
all dependencies are pinned
Details
Reason
24 commit(s) and 8 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 4/5 approved changesets -- score normalized to 8
Reason
8 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More