npm-mssql v1.0.2
Installation
npm install --save npm-mssqlEnsure the following environment variables are added to your secrets:
MSSQL_SERVER- IP Address of
vin65masterdatabase
- 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 makeMssqlClientconstructor available to your code.To create a new
MssqlClientinstance, callnew MssqlClient(config)whereconfigis a required hash object that contains the following properties:datasourceserverusernamepassword
The initially provided config can also be updated via called
.setConfig(config)whereconfigis a required hash object containing the properties listed above.To execute a query, call
.execute(query, params), wherequeryis a requiredstringthat is a validSQLstatement, andparamsis optional hash object containing parameters for theSQLquery.
MssqlConfig
Add
const MssqlConfig = require('npm-mssql/objects/MssqlConfig');to makeMssqlConfigconstructor available to your code.To get an instance of
MssqlConfig, callMssqlConfig.singleton(environment), whereenvironmentis an optionalstring, which can be specified to beproductionto fetchProductionDatasources information fromvin65masterdatasource. Otherwise,stagingdatasource information will be returned using the providedMSSQL_SERVERenvironment 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), wheredatasourceis a requiredstringthat is the name of datasource.The name of the master datasource is available via
.masterDatasource()method. Currently, it's set tovin65master.