0.0.1 • Published 4 years ago

@juntoz/mssql-utils v0.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

Introduction

This small library is intended to help start with mssql in nodejs.

Right now, the only class available is the MsSqlPoolWrapper class which help pre-configure a mssql ConnectionPool object that you can use in your application.

The recommended way to create the wrapper is as a singleton because inside it will create one pool and reuse it.

The wrapper additionally will start listening on both global and pool events and output them to the console. (TODO: output to a log or a listener).

It basically fills the connection pool with the necessary listeners so it does not fail with "Uncaught exception" errors.

How to install?

npm i @juntoz/mssql-utils

How to use?

Create your singleton and reuse in every execution

const mssql = require('mssql');
const { MsSqlPoolWrapper } = require('@juntoz/mssql-utils');

const sqlPool = new MsSqlPoolWrapper('<your connection string to mssql>');

async function getDataFromDb1() {
    const pool = await sqlPool.connect();
    const req = new mssql.Request(pool);
    const result = await req
        .input('arg1', 1)
        .execute('usp_mystoredproc');
    return result.recordset;
}

async function getDataFromDb2() {
    const pool = await sqlPool.connect();
    const req = new mssql.Request(pool);
    const result = await req
        .input('arg1', 1)
        .execute('usp_mystoredproc2');
    return result.recordset;
}