This is a node.js wrapper module for the mysql node module, it's written in JavaScript.
But why this module?
This module helps me to create / handle very easy more than one database connection with core features implementation.
The module is currently only available on github, so use the following command to install:
$ npm install https://github.com/MoonLiightz/simple-mysql-wrapper/archive/v0.1.1.tar.gz --save
const mysql_helper = require('simple-mysql-wrapper');
let anyDatabase = new mysql_helper({
host: '127.0.0.1',
port: 3306,
user: 'db_user',
password: 'db_password',
database: 'db_database',
connectTimeout: 10000 // milliseconds
});
anyDatabase.connect((err) => {
if(err) console.log(err.message);
else {
// Connection to database was successfully, run any query now
anyDatabase.runQuery('SELECT * FROM users', (err, rows) => {
if(err) console.log(err.message);
else console.log(rows);
// Don't forget to disconnect from database when you are ready
anyDatabase.disconnect((err) => {
if(err) console.log(err.message);
else console.log('Now we are disconnected')
})
});
}
});
There are only three methods.
Start trying to connect to the database.
function(err)
Callback of mysql connect
Execute an mysql query
String
SQL string of the query
function(err, rows)
Callback of mysql query
Close the database connection.
function(err)
Callback of mysql disconnect
- You find some examples here: simple-mysql-wrapper/examples/
- For more details about the configuration or anything else look at the original mysql module.