# mssql-helper

> data access layer for mssql that allows connection reuse per request or context, syncronization of commands

Latest version **0.2.1** (published 2015-10-09) · 0 weekly downloads

## Install

```sh
npm install mssql-helper
pnpm add mssql-helper
yarn add mssql-helper
bun add mssql-helper
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2015-10-09 |
| First published | 2014-10-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marcos Mellibovsky |
| Maintainers | mellibo |
| Keywords | mssql, helper, dal, sql server, ms sql, transaction, data access layer |

## Links

- npm: https://www.npmjs.com/package/mssql-helper
- Repository: https://github.com/mellibo/mssql-helper
- Issues: https://github.com/mellibo/mssql-helper/issues
- npm.io page: https://npm.io/package/mssql-helper

## Dependencies (3)

- [mssql](https://npm.io/package/mssql.md) ^1.2.0
- [moment](https://npm.io/package/moment.md) ^2.8.3
- [winston](https://npm.io/package/winston.md) ^0.8.1

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads
- [react-native-modal-translucent-axton](https://npm.io/package/react-native-modal-translucent-axton.md) — 4 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2015-10-09
- 0.2.0 — 2014-10-28
- 0.1.4 — 2014-10-24
- 0.1.3 — 2014-10-24
- 0.1.2 — 2014-10-24
- 0.1.1 — 2014-10-18
- 0.1.0 — 2014-10-17
- 0.0.7 — 2014-10-14
- 0.0.6 — 2014-10-10
- 0.0.5 — 2014-10-08
- 0.0.4 — 2014-10-08
- 0.0.3 — 2014-10-08
- 0.0.2 — 2014-10-06
- 0.0.1 — 2014-10-06

## README

# mssql-helper

Microsoft Sql Server helper that support transactions per request, query queueing.

For use with Node.js and mssql: https://github.com/patriksimek/node-mssql

## Background

implement a simple layer for mssql supporting queueing commands per request (or per object used as context)

## Install

`npm install mssql-helper`

## Usage

```javascript
var db = require('mssql-helper');

var dbConfig={};
dbConfig.user= 'test';
dbConfig.password= 'test';
dbConfig.server= 'localhost';
dbConfig.database = 'test';

var context = req; // the request obect or any object that you want to use to share a connection and syncronice commands. 
context.dbConfig = dbConfig;
db.executeQuery(context, 'SELECT TOP 1 * FROM test WHERE id = @id', [{name: 'id', value : '1'}], function (err, recordset) {
  console.log(recordset[0].id);
  console.log(recordset[0].test);
});

```
### Transaction

	var contexto = {}; //can be the request object
	contexto.dbConfig = {user: 'test', password:'test', server: 'localhost', database: 'test'}
	db.beginTran(contexto,function(err){
		console.log('BEGIN TRAN');
	});
	db.executeQuery(contexto, "WAITFOR DELAY '00:00:01'; insert into Table VALUES(1, 'text 1')", function(err, recordset){
		console.log('first INSERT');
	});
	db.executeQuery(contexto, "insert into Table VALUES(2, 'text 2')", function(err, recordset){
		console.log('second INSERT');
	});
	db.commitTran(contexto, function(err){
		console.log('commit');
	});
## How it works


## API

### client.executeQuery(context, sql, [params, callback])

push 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.

### client.run(cn, sql, [params, callback])

execute a command without queuing.

### client.isInTransaction(context)

return true if it is in transaction.

### client.beginTran(context, [callback])

begin a transaction.

### client.commitTran(context, [callback])

commit a transaction.

### client.rollbackTran(context, [callback])

rollback a transaction.

---
_Source: https://npm.io/package/mssql-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
