-
Notifications
You must be signed in to change notification settings - Fork 0
GetSqlMethod
Michael J. Ryan edited this page May 21, 2015
·
1 revision
The azure-config-util object instance presents an sql(name) method that returns a promise, that will resolve to an mssql-ng connection instance.
This method uses storage(...) to establish an azure-storage-simple connection wrapper.
In order to use the sql(name) method, you will have to install the following modules in addition to azure-config-util
| Section | Key | JsonValue |
|---|---|---|
| sql | myconnection | {...} |
- The shown
"name"field in theJsonValueis optional when it matches theKey.
The JsonValue should be a configuration object for mssql connections.
var sql = require('mssql-ng');
var db = await azureUtil.sql('myconnection');\\ simple query template processor, returns promise for a result
db.query`
--you can specify output parameters (name, type, initialValue)
SET ${sql.output('param1', sql.NVarChar(sql.MAX)} = 'output param value'
--input parameters can be auto-detected, or explicit
SELECT ${someVariable1} [Test1],
${sql.input('param2', sql.Decimal, someNumberVariable)} [Test2]
`.then(function(result){
//request parameters attached to result.parameters
console.log('output @param1', result.parameters.param1.value);
//recordset/rows attached to result.recordset
console.log('row 1, column 1', result.recordset[0].Test1);
console.log('row 1, column 2', result.recordset[0].Test2);
}).catch(console.error);db.queryStream`
SELECT *
FROM SomeTable
WHERE Foo=${someBar}
AND Baz=${true}
AND Something <= ${new Date()}
`.then(function(request){
return new Promise(function(resolve,reject){
recordStream
.pipe(itemProcessor)
.on('error',reject)
.on('end',resolve)
.resume();
});
})
.catch(function(err){
console.error(err);
process.exit(200);
});var request = new sql.Request(db);
...