mysql-query

2.0.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i mysql-query

Weekly Downloads

20

Version

2.0.0

License

MIT

Last publish

Collaborators

  • ohar