node-sql
A simple node-style callback wrapper for the wonderful Tedious driver.
Just call the exec
function with a query, or sproc
with a stored procedure, and get back an Array of JSON objects.
Query in, JSON out.
exec(query, config, callback) Execute arbitrary SQL
query: String - standard SQL query e.g. 'Select * From tbl'
.
config: Object - standard tedious config object.
callback: Function - standard node callback, returns (err, result)
. Where err = Error, and result = the query results.
var nodeSQL = //standard tedious config object : http://tediousjs.github.io/tedious/api-connection.html#function_newConnectionvar config = userName: processenvUSERNAME password: processenvPASSWORD server: 'MyServer' domain: 'DOMAIN'//result has data as an Array of JSON objects with column name => column valueapp
sproc(name, params, config, callback) Call a stored procedure
name: String - stored procedure name e.g. MyDB.dbo.GetDataById
.
params: Object - Key Value pairs of parameter name to parameter value, e.g. { ID : 4 }
(the type is inferred).
config: Object - standard tedious config object.
callback: Function - standard node callback, returns (err, result)
. Where err = Error, and result = the query results.
var nodeSQL = //standard tedious config object : http://tediousjs.github.io/tedious/api-connection.html#function_newConnectionvar config = userName: processenvUSERNAME password: processenvPASSWORD server: 'MyServer' domain: 'DOMAIN'//result has data as an Array of JSON objects with column name => column valueapp
tvp(name, params, config, callback) Call a table-value parameter sproc
name: String - stored procedure name e.g. MyDB.dbo.GetDataById
.
paramName: String - Name of the Table-Value Parameter, e.g. Todos
.
table: Array of Objects - Follow the pattern here tedious tvp object.
config: Object - standard tedious config object.
callback: Function - standard node callback, returns (err, result)
. Where err = Error, and result = the query results.
var nodeSQL = //standard tedious config object : http://tediousjs.github.io/tedious/api-connection.html#function_newConnectionvar config = userName: processenvUSERNAME password: processenvPASSWORD server: 'MyServer' domain: 'DOMAIN'//result has data as an Array of JSON objects with column name => column valueapp
getColumnNames(query, config, callback) Get SQL column names
query: String - standard SQL query e.g. 'Select * From tbl'
.
config: Object - standard tedious config object.
callback: Function - standard node callback, returns (err, result)
. Where err = Error, and result = the query results.
var nodeSQL = //standard tedious config object : http://tediousjs.github.io/tedious/api-connection.html#function_newConnectionvar config = userName: processenvUSERNAME password: processenvPASSWORD server: 'MyServer' domain: 'DOMAIN'//result has data as an Array of column namesapp
Installation
$ npm install node-sql --save