Skip to content

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

License

Notifications You must be signed in to change notification settings

Ohar/mysql-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published