Package Exports
- mag-node-sql
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mag-node-sql) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mag-node-sql
A utility library that allows you to easily interact with MAG's SQL Server in Node.js. It is a wrapper around mssql.
Getting Started
Install via npm:
npm i --save mag-node-sql
Require the library in your code:
const MagSQL = require('./NodeSQL');
Create an instance of the "MagSQL" class. Options parameter is optional (Defaults shown below):
const options = {
database: 'GISSANDBOX',
server: 'SQL'
};
const sql = new MagSQL(options);
Use one of the methods on your new instance. (See available functions below)
Available Methods
- RunQuery
- Runs a string as a sql query and returns the results as a promise
- Example:
- Runs a string as a sql query and returns the results as a promise
- ArrayToSQLTable
- Adds a SQL Table and adds all rows from the js array that is passed in *(Warning) This function will drop the table if the name passed in already exists!
- Example:
let testData = [ { firstName: 'tim', lastName: 'johnson', age: 34 }, { firstName: 'marcia', lastName: 'brown', age: 28 } ]; sql .ArrayToSQLTable(testData, 'test') .then(result => { console.log(result); }) .catch(err => { console.log(err); });
- Example:
- Adds a SQL Table and adds all rows from the js array that is passed in *(Warning) This function will drop the table if the name passed in already exists!
- DropTable
- Drops a sql table by name if it exists
- Example:
sql.DropTable('test').then(res => console.log('table dropped'));
- Example:
- Drops a sql table by name if it exists
Dependencies
- msnodesqlv8 - ms sql server driver to allow integrated connection
- mssql - interface with ms sql server
Links
Authors
- Jack Fairfield
License
This project is licensed under the MIT License.