mag-node-sql

1.0.23 • Public • Published

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:
  • 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'));

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.

Readme

Keywords

Package Sidebar

Install

npm i mag-node-sql

Weekly Downloads

7

Version

1.0.23

License

ISC

Unpacked Size

12.4 kB

Total Files

6

Last publish

Collaborators

  • jefairfi