{"_id":"@alastair/mssql-helper","_rev":"4-9f8e3fb19c2fcb699a7fa732fed271a6","name":"@alastair/mssql-helper","description":"data access layer for mssql that allows connection reuse per request or context, syncronization of commands","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.3":{"name":"@alastair/mssql-helper","version":"0.1.3","description":"data access layer for mssql that allows connection reuse per request or context, syncronization of commands","author":{"name":"Marcos Mellibovsky","email":"mellibo@arsoft.com.ar"},"main":"db.js","repository":{"type":"git","url":"git+https://github.com/mellibo/mssql-helper.git"},"licenses":[{"type":"MIT","url":"http://opensource.org/licenses/mit-license.php"}],"engines":{"node":">=0.6"},"bugs":{"url":"https://github.com/mellibo/mssql-helper/issues"},"homepage":"https://github.com/mellibo/mssql-helper","keywords":["mssql","helper","dal","sql server","ms sql","transaction","data access layer"],"dependencies":{"moment":"^2.8.3","mssql":"^1.2.0","winston":"^0.8.1"},"devDependencies":{"chai":"^1.9.2","mocha":"^1.21.4"},"gitHead":"7166becec30ffcda39c970d129985b44f913fdc8","_id":"@alastair/mssql-helper@0.1.3","scripts":{},"_shasum":"00fdd5fecb3ba1f1c0968f7c36eaa137b6b53e37","_from":".","_npmVersion":"2.11.3","_nodeVersion":"0.12.7","_npmUser":{"name":"alastair","email":"alastair@fleep.io"},"dist":{"shasum":"00fdd5fecb3ba1f1c0968f7c36eaa137b6b53e37","tarball":"https://registry.npmjs.org/@alastair/mssql-helper/-/mssql-helper-0.1.3.tgz","integrity":"sha512-yTOyQk/DCShZVnCwOoKdKR+uWjZiokElvwDbck9jVHId1Pm6S2clrHdUdGhYxUqg+axmIO05NgKU7HiHzl44pg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFRHkZkG663MQYRqQuoJPD2Q3ztiDNIxdQ5oFR81ETTKAiEApasJUyOX7YUWvThzohtQd17Ym5MLafnDkJ7wBiEVsTA="}]},"maintainers":[{"name":"alastair","email":"alastair@fleep.io"}]}},"readme":"# mssql-helper\r\n\r\nMicrosoft Sql Server helper that support transactions per request, query queueing.\r\n\r\nFor use with Node.js and mssql: https://github.com/patriksimek/node-mssql\r\n\r\n## Background\r\n\r\nimplement a simple layer for mssql supporting queueing commands per request (or per object used as context)\r\n\r\n## Install\r\n\r\n`npm install mssql-helper`\r\n\r\n## Usage\r\n\r\n```javascript\r\nvar db = require('mssql-helper');\r\n\r\ndb.config.user= 'test';\r\ndb.config.password= 'test';\r\ndb.config.server= 'localhost';\r\ndb.config.database = 'test';\r\n\r\nvar context = req; // the request obect or any object that you want to use to share a connection and syncronice commands. \r\ndb.executeQuery(context, 'SELECT TOP 1 * FROM test WHERE id = @id', [{name: 'id', value : '1'}], function (err, recordset) {\r\n  console.log(recordset[0].id);\r\n  console.log(recordset[0].test);\r\n});\r\n\r\n```\r\n### Transaction\r\n\r\n\tvar contexto = {}; //can be the request object\r\n\tdb.beginTran(contexto,function(err){\r\n\t\tconsole.log('BEGIN TRAN');\r\n\t});\r\n\tdb.executeQuery(contexto, \"WAITFOR DELAY '00:00:01'; insert into Table VALUES(1, 'text 1')\", function(err, recordset){\r\n\t\tconsole.log('first INSERT');\r\n\t});\r\n\tdb.executeQuery(contexto, \"insert into Table VALUES(2, 'text 2')\", function(err, recordset){\r\n\t\tconsole.log('second INSERT');\r\n\t});\r\n\tdb.commitTran(contexto, function(err){\r\n\t\tconsole.log('commit');\r\n\t});\r\n## How it works\r\n\r\n\r\n## API\r\n\r\n### client.executeQuery(context, sql, [params, callback])\r\n\r\npush the command into a queue made in context object and run it. The context param can be the request to use a connection (or transaction) per request. If there is no active connection in the context, a connection is created.\r\n\r\n### client.run(cn, sql, [params, callback])\r\n\r\nexecute a command without queuing.\r\n\r\n### client.isInTransaction(context)\r\n\r\nreturn true if it is in transaction.\r\n\r\n### client.beginTran(context, [callback])\r\n\r\nbegin a transaction.\r\n\r\n### client.commitTran(context, [callback])\r\n\r\ncommit a transaction.\r\n\r\n### client.rollbackTran(context, [callback])\r\n\r\nrollback a transaction.\r\n","maintainers":[{"email":"ali.c.taft@gmail.com","name":"alastair"}],"time":{"modified":"2022-06-12T14:27:30.833Z","created":"2015-09-06T19:20:45.425Z","0.1.3":"2015-09-06T19:20:45.425Z"},"homepage":"https://github.com/mellibo/mssql-helper","keywords":["mssql","helper","dal","sql server","ms sql","transaction","data access layer"],"repository":{"type":"git","url":"git+https://github.com/mellibo/mssql-helper.git"},"author":{"name":"Marcos Mellibovsky","email":"mellibo@arsoft.com.ar"},"bugs":{"url":"https://github.com/mellibo/mssql-helper/issues"},"readmeFilename":"readme.md"}