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); });
- 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.