Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

18 Commits

Repository files navigation

node-sqlserver

A wrapper for the Tedious driver. This wrapper can turn parameterized queries into function calls that support either the standard callback-style of Tedious or return Promises. The idea is to create an object that encapsulates a list of queries such that you get behaviour similar to a data access object and the particulars of the query are abstracted away.

Additionally, the wrapper implements SQL connection pooling. In apps that have multiple users or are otherwise highly asynchronous, pooling will prevent bottlenecks when dealing with multiple queries.

Installation

This module is not currently registered with NPM. In order to install, you must use the following command:

npm install git+https://github.com/unidyne/node-sqlserver.git

Usage Example

constfs=require('fs'),{SQLServerPool}=require('node-sql-server');// load tedious config from a JSON fileconstsqlConfig=JSON.parse(fs.readFileSync('./etc/sqlserver.conf'));// connect to SQL Server using this modulesqlServer=newSQLServerPool(sqlConfig);// load queries (could use a JSON file)constsqlQueries=sqlServer.loadQueries([{id: "getItems",asPromise: true,params: [{"name": "id","type": "int","options": {}}],sql: "SELECT id, name FROM items WHERE cat_id = @id",flatten: true// return field values without metadata},{id: "getAllCategories",asPromise: false,params: [],sql: "SELECT id, name FROM category"}]);// query using callbacksqlQueries.getAllCategories({},async(err,rowCount,rows)=>{if(err)return;for(vari=0;i<rows.length;i++){// query using promise// getAllCategories is NOT flattened, so must use <field>.valuevaritems=awaitsqlQueries.getItems(rows[i].id.value);// getItems IS flattened, so access value through field namefor(varj=0;j<items.length;j++)console.log("Item: "+items[j].name);}});

About

Wrapper for Tedious that turns queries into function calls. Also has connection pooling.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages