Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vin65/npm-mssql
NodeJS npm module to connect to MSSQL
https://github.com/vin65/npm-mssql
mssql npm npm-package
Last synced: 3 months ago
JSON representation
NodeJS npm module to connect to MSSQL
- Host: GitHub
- URL: https://github.com/vin65/npm-mssql
- Owner: Vin65
- Created: 2017-11-27T23:28:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T14:17:15.000Z (over 1 year ago)
- Last Synced: 2024-10-14T09:27:19.122Z (3 months ago)
- Topics: mssql, npm, npm-package
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 2
- Watchers: 24
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Installation
* `npm install --save npm-mssql`* Ensure the following environment variables are added to your secrets:
* `MSSQL_SERVER`
- IP Address of `vin65master` database
* `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 make `MssqlClient` constructor available to your code.* To create a new `MssqlClient` instance, call `new MssqlClient(config)` where `config` 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)` where `config` is a required hash object containing the properties listed above.
* To execute a query, call `.execute(query, params)`, where `query` is a required `string` that is a valid `SQL` statement, and `params` is optional hash object containing parameters for the `SQL` query.
### `MssqlConfig`
* Add `const MssqlConfig = require('npm-mssql/objects/MssqlConfig');` to make `MssqlConfig` constructor available to your code.* To get an instance of `MssqlConfig`, call `MssqlConfig.singleton(environment)`, where `environment` is an optional `string`, which can be specified to be `production` to fetch `Production` Datasources information from `vin65master` datasource. Otherwise, `staging` datasource information will be returned using the provided `MSSQL_SERVER` environment variable.
* **DO NOT** call `new MssqlConfig()` directly.
* _If you need to destroy the singleton instance, call `MssqlConfig.resetSingleton()`._* To fetch datasource config for a given datasource name, such as `pinewines`, call `singleton.for_(datasource)`, where `datasource` is a required `string` that is the name of datasource.
* The name of the master datasource is available via `.masterDatasource()` method. Currently, it's set to `vin65master`.