1.0.0 • Published 9 years ago

mysql-simplify v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

mysql-wrapper

Work in progress.

Installation Instruction -

npm install mysql-wrapper --save

Usage -

To create a new Query

const mysql = require('mysql-wrapper').Query;

const userID = 10;

/**
 * Each query is an instance of the Query object
 */
let myQuery = new mysql();

    // Set host manually or through environment variables
    myQuery.setDataHost('url-to-host');
    // Set username manually or through environment variables
    myQuery.setDataUser('username');
    // Set password manually or through environment variables
    myQuery.setDataPassword('password');
    // Set datasource manually or through environment variables
    myQuery.setDataSource('test');
    // Pass in the query statement
    myQuery.setSql('SELECT * FROM users WHERE id = :id;');
    // Escape any variables
    myQuery.addParam('id', userID);
    // execute as a transaction
    myQuery.execute().then(
        (resultArray) => {
            if (resultArray && resultArray.length) {
                doSomethingWith(resultArray);
            } else {
                doSomethingElse();
            }
        }
    );