mysql2-json-sql
MySQL2 wrapper for Node.js with json interface. Supports prepared transactional
Installing with npm
npm install mysql2-json-sql
Usage
const mysql = require('mysql2-json-sql');
const db = mysql({
host: 'localhost',
user: 'test',
password: '',
database: 'test_db',
waitForConnections: true,
connectionLimit: 5,
queueLimit: 0
});
const test = db.test_db.table('test');
const tables = await db.test_db.tables();
test.find({_id:12},(err,result)=>{
console.log(result);
})
tables.test.find({_id:12},(err,result)=>{
console.log(result);
})
db.test_db.test.find({_id:12},(err,result)=>{
console.log(result);
})
response
[{
"_id":12, "name": "test"
}]
Inserting documents
var data = { _id:13, name: 'world'};
db.test_db.test.insert(data, function (err, newDoc) {
});
we can do bulk-insert data also
db.test_db.test.insert([{ _id: 14, name: 'hello' }, { _id: 15, name:'word' }], function (err, newDocs) {
});
Finding data
db.test_db.test.find({ name: 'world' }, function (err, docs) {
});