
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
mysql-composer
Advanced tools
One of the duty of my job is to write web scraper -- scrape data and store to mysql tables. And most of the time, the origin tables are not created by myself. It's inefficient to model these tables like sequelize do. All I want is having direct access to the tables and being efficient. That's why I develop mysql-composer.
If you are looking for a more powerful tool, sequelize may be a better choice.
npm i -S mysql-composer
mysql-composer is a simple tool for you to execute sql on mysql database.
const Composer = require('mysql-composer')
const mysql = require('mysql')
const connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
const composer = new Composer(connection)
insert(config,callback,inspect)
{
table:'tableName', //require
data:{ //require
field1:'value1',
field2:'value2'
},
ignore:true,//optional,defaults to true
onDuplicateKeyUpdate:{field1:'value1',
field2:function(){
return 'field1+1'
}},//optional
}
callback(err,result)inspect(sql)example:
//insert ignore into user (`name`,`age`) values ('Tom','18')
composer.insert({
table:'user',
data:{
name:'Tom',
age:'18'
}
},function(err,result){
//your code after sql is executed
},function(sql){
console.log(sql)
})
update(config,callback,inspect)
config:
{
table:'tableName', //require
data:{ //require
field1:'value1',
field2:function(){
return 'field2+1'
}
},
where:'id=1' //require,if you need to update all, you should explicitly set 'where' to 1.
}
callback: will be called when sql is executed: callback(err,result)
inspect: will be called with generated sql : inspect(sql)
example:
//update `user` set age='18' where id=1
composer.update({
table:'user',
data:{
age:'18'
},
where:"id=1"
},function(err,result){
//your code after sql is executed
},function(sql){
console.log(sql)
})
query(sql,callback,inspect)
callback(err,result)inspect(sql)example:
//update `user` set age='18' where id=1
composer.query('select * from user where id=1',function(err,result){
//your code after sql is executed
},function(sql){
console.log(sql)
})
beginTransaction(callback)
callback(err)example:
composer.beginTransaction(function(err){
if(err)throw err
composer.insert({
table:'user',
data:{
name:'Tom',
age:'18'
}
},function(err,result){
if(err)return composer.rollback(function(){
throw err
})
composer.commit(function(err){
if(err)return composer.rollback(function(){
throw err
})
console.log('success')
})
})
})
rollback(callback)
callback(err)commit(callback)
callback(err)mysql-composer supports promise, it will be convenient if you like to use mysql-composer with co or async/await.
if you do not provide a callback in the apis above, they will return a promise:
var promise = composer.update({
table:'name',
where:'id=2',
data:{
field1:'value1',
field2:'value2'
}
})
promise.then(function(result){
}).catch(function(err){
})
FAQs
A simple nodejs mysql syntax composer for insert and update syntax.
The npm package mysql-composer receives a total of 195 weekly downloads. As such, mysql-composer popularity was classified as not popular.
We found that mysql-composer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.