npm-mssql
v1.0.2
Published
MSSQL Client and Models NPM Module
Downloads
6
Keywords
Readme
Installation
npm install --save npm-mssql
Ensure the following environment variables are added to your secrets:
MSSQL_SERVER
- IP Address of
vin65master
database
- IP Address of
MSSQL_USERNAME
- Username for accessing all databases
MSSQL_PASSWORD
- Password for username for accessing all databases
Usage
MssqlClient
Add
const MssqlClient = require('npm-mssql/objects/MssqlClient');
to makeMssqlClient
constructor available to your code.To create a new
MssqlClient
instance, callnew MssqlClient(config)
whereconfig
is a required hash object that contains the following properties:datasource
server
username
password
The initially provided config can also be updated via called
.setConfig(config)
whereconfig
is a required hash object containing the properties listed above.To execute a query, call
.execute(query, params)
, wherequery
is a requiredstring
that is a validSQL
statement, andparams
is optional hash object containing parameters for theSQL
query.
MssqlConfig
Add
const MssqlConfig = require('npm-mssql/objects/MssqlConfig');
to makeMssqlConfig
constructor available to your code.To get an instance of
MssqlConfig
, callMssqlConfig.singleton(environment)
, whereenvironment
is an optionalstring
, which can be specified to beproduction
to fetchProduction
Datasources information fromvin65master
datasource. Otherwise,staging
datasource information will be returned using the providedMSSQL_SERVER
environment variable.- DO NOT call
new MssqlConfig()
directly. - If you need to destroy the singleton instance, call
MssqlConfig.resetSingleton()
.
- DO NOT call
To fetch datasource config for a given datasource name, such as
pinewines
, callsingleton.for_(datasource)
, wheredatasource
is a requiredstring
that is the name of datasource.The name of the master datasource is available via
.masterDatasource()
method. Currently, it's set tovin65master
.