mysql-json
=========
Simple Node.js mysql module using [mysql] (https://github.com/mysqljs/mysql)
Installation
npm install mysql-json
Declaration
var MysqlJson = require('mysql-json');
var mysqlJson = new MysqlJson(options);
Methods
All methods take a callback which is called with 2 parameters (err, response)
mysqlJson.connect(callback);
mysqlJson.query(mysqlQuery, callback);
mysqlJson.findByPrimaryKey(tableName, id, callback);
mysqlJson.insert(tableName, dataToInsert, callback);
mysqlJson.update(tableName, data, conditions, callback);
mysqlJson.delete(tableName, conditions, callback);
Condition Objects has to be build with this schema :
{
column1: {operator:'=', value:'test'},
column2: {operator:'>', value:29},
}
Usage
var MysqlJson = require('mysql-json');
var mysqlJson = new MysqlJson({
host:'127.0.0.1',
user:'root',
password:'root',
database:'myDatabase'
});
mysqlJson.query("SELECT * FROM users WHERE login LIKE '%admin%'", function(err, response) {
if (err) throw err;
console.log(response);
});
mysqlJson.findByPrimaryKey('myTable', 1, function(err, response) {
if (err) throw err;
console.log(response);
});
mysqlJson.insert('myTable', {
login:'root',
firstName:'John',
lastName:'Doe',
age:45
}, function(err, response) {
if (err) throw err;
console.log(response);
});
mysqlJson.update('myTable',
{lastName:'Foo', age:27},
{login:{operator:'=', value:'root'}},
function(err, response) {
if (err) throw err;
console.log(response);
});
mysqlJson.delete('myTable', {
login:{operator:'=', value:'root'}
}, function(err, response) {
if (err) throw err;
console.log(response);
});
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.
Release History