关于nodejs中的增删改查
Posted is-meeeee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于nodejs中的增删改查相关的知识,希望对你有一定的参考价值。
1.增加
router.post(‘/insert‘,function(req,res)
var name = req.body.name;
var num = req.body.num;
var job = req.body.job;
var sql = `insert into user (name,num,job) values ("$name","$num","$job")`
mc.query(sql,function(err,data)
res.send(data);
)
)
2.删除
router.post(‘/delete‘,function(req,res)
var id = req.body.id;
var sql = `delete from user where id = $id`;
mc.query(sql,function(err,data)
res.send(data);
)
)
3.修改
router.post(‘/update‘,function(req,res)
var id = req.body.id;
var num = req.body.num;
var name = req.body.name;
var job = req.body.job;
var sql = `update user set name="$name",num="$num",job="$job" where id=$id`;
mc.query(sql,function(err,data)
res.send(data);
)
)
4.查询
router.post(‘/main‘,function(req,res)
var sql = `select * from user where name like “%name%“`;
mc.query(sql,function(err,data)
res.send(data);
)
)
以上是关于关于nodejs中的增删改查的主要内容,如果未能解决你的问题,请参考以下文章