Simple wrapper with additional functionality over node-mysql.
npm i node-mysql-connect --save
Minimal config:
var config = {
user: '<your_user>',
password: '<your_password>',
database: '<your_database_name>'
};
Include and initialize module:
var connection = require('node-mysql-connect')(config);
Do query:
connection.query("SELECT * FROM <your_table>", function (err, data) {
if (err) throw err;
// working with data ...
});
Query with params:
connection.query("SELECT * FROM <your_table> WHERE a = ? AND b = ?", [a, b], function (err, data) {
if (err) throw err;
// working with data ...
});
logger
- enable logging:
var config = {
//...
logger: console.log // for example
};