Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.13 KB

README.md

File metadata and controls

56 lines (40 loc) · 1.13 KB

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