mysql-query

NodeJS wrapper for MySQL query, based on “mysql” package


Keywords
mysql, query
License
MIT
Install
npm install mysql-query@2.0.0

Documentation

mysql-query

NodeJS wrapper for MySQL query, based on “mysql” package

NPM

How to use

Let`s say you have MySQL connection as separated module like this

'use strict';

const mysql = require('mysql');

let mySqlConnection = mysql.createConnection(
    {
      host:     'http://example.com',
      port:     80,
      user:     'user',
      password: 'password',
      database: 'database',
      timezone: 'UTC',
    }
);

module.exports = mySqlConnection;

Then you can use mysql-query like this

'use strict';

const mysqlQuery      = require('mysql-query'),
      mysqlConnection = require('./mysql-connection');

function foo () {
  const resolveHandler = rows => rows,
        rejectHandler = err => {
            console.error('NOOOOOOO', err);
            return err;
        },
        query = `
          SELECT *
          FROM test 
          WHERE answer = 42
        `;

  return mysqlQuery(mysqlConnection, query, resolveHandler, rejectHandler)
    .then(rows => console.log);
}