exframe-mssql
v1.0.0
Published
Framework module for MSSQL connections
Readme
exframe MSSQL Module
A lightweight wrapper around the mssql (tedious) driver to provide MSSQL database connections for the Harmony Framework.
Features
- Lightweight MSSQL connection pooling
- Active-query health check registered with
exframe-health - Exframe-Service Graceful Shutdown
- Raw
mssqlmodule access for parameterized query/bulk insert type helpers
Use
const mssql = require('exframe-mssql');Full Example
const mssql = require('exframe-mssql');
const db = mssql.init({
name: 'myDb',
server: 'localhost',
port: 1433,
user: 'username',
password: 'password',
database: 'myDatabase'
});
await db.connect();
const { recordset } = await db.pool.request().query('SELECT 1+1');Properties
- Sql Core
mssqllibrary export (top-level and per-instance) — use for type helpers likeSql.Int,Sql.NVarChar,Sql.Table, andSql.Transaction.ISOLATION_LEVELS.
Methods
init(options)
mssql.init({ name: 'myDb', server, user, password, database });Parameter Values
|Parameter|Required|Details|
|---|---|---|
|name|No|Instance Name - Defaults to a generated short id. Used to namespace the health check (mssql-<name>) and exframe-service resource (exframe-mssql-<name>)|
|register|No|Defaults to true. When false, skips registering the health check with exframe-health and the shutdown resource with exframe-service (useful for wrappers that manage their own registration)|
|...options|Yes|mssql Options - See mssql Docs for information and connection specific options|
Returns an object with:
|Property|Details|
|---|---|
|name|Resolved instance name|
|pool|Getter; the underlying mssql.ConnectionPool once connect() has resolved (undefined before)|
|Sql|Raw mssql module|
|connect()|Creates the pool, connects, and registers the exframe-service shutdown resource. Call once per instance|
|mssqlCheck()|Health check function; resolves {status: 200, message: 'OK'} or rejects {status: 503, message: 'Error connecting to MSSQL'}. Also registered automatically with exframe-health|
Tests
npm run test