==========
An SQL Server access library with Q promises!
- Added a StoreProcedure Function
First, edit the locally included config.json file to your sql server settings. The configuration is the same as if you were using the mssql module available on NPM.
Now you have three functions:
This function returns a promise for an array of objects containing the results of the query.
sqlpromise = require('sqlpromise');
sqlpromise.doQuery('select * from users').then (function (results) {
console.log (results[0].username);
});
This function will resolve with Q promise. doInputProcedure() will resolve with an array of JSON records.
Option - an object with properties to describe the Stored Procedure to call (see example below).
** StoreProcedure = Name of the stored procedure as a String
Example
{
"Param" : "",
"Type" : "",
"Value" : ""
}
var sqlpromise = require('sqlpromise');
var Option = {
"Param" : "@username", //without the @
"Type" : sql.VarChar(), //see the mssql documentation for types
"Value" : "xenlias" //value of the query
}
sqlpromise.doInputProcedure(Option, 'getUsers').then (
function (records) {
//your logic here
}
);
This function will return a Q promise.
doUpdateQuery() works the same as doQuery, but the returned promise resolves with the string "success" or a rejection reason. Use this function for queries that do UPDATEs, INSERTs and DELETEs.
Enjoy!