【发布时间】:2022-01-26 04:25:50
【问题描述】:
User.createuser = (req, result) => {
sql.query("INSERT INTO Users SET ?", req, (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
return;
}
// if (await User.findOne({ where: { username: req.body.username } })) {
// throw 'Username "' + req.body.username + '" is already taken';
// }
console.log("created User: ", { id: res.insertId, ...req });
result(null, { id: res.insertId, ...req });
});
};
api 创建路由(post 方法)的示例 json 对象
{
"username": "seve",
"user_name": "sev123",
"user_surname": "avcı",
"email": "sevre@gmail.com",
"user_type": "user",
"password": "123456"
}
“插入用户集?”我在代码中使用的查询,我希望它作为一个存储过程,我希望它自己处理存储过程 id,这个代码的存储过程的等价物是什么?
【问题讨论】:
-
您想按原样向查询提供显示的 JSON 并将其值插入到相应的表列中吗?如果是这样,那么发布 precise MySQL 版本。并澄清 JSON 结构是静态的(所有显示的属性始终存在),还是可能不同?
标签: mysql sql node.js mysql-workbench