【发布时间】:2015-08-30 02:05:00
【问题描述】:
万事如意,
我正在尝试将一些旧的 php 代码转换为 Node,并且部分旅程一直在尝试找出对我的数据库执行 sql 查询的最佳方法(我正在使用 SQL,因此我可以移植现有的数据库结束)。
我已经让它们工作了,但遇到了“末日金字塔”问题,这是后续的范围问题(即返回的值不适用于后续的“then”)。
我在这里的代码类型的示例是:(dbPool.queryOPromise 返回包装在承诺中的查询)
dbPool.queryOPromise(query)
.then(function(result){
console.log(result);
var query = {
sql:"INSERT INTO newusers (newuserid, ipaddress, email) VALUES (?,?,?)",
values: [newuserid, ipAddress, email]
};
dbPool.queryOPromise(query)
.then(function(value){
console.log(value);
if(value.code==200) {
res.status(200).json({code:200, status:"New User Created"});
} else {
res.status(400).json({code:value.code, status:"Error creating new user: ".value.status});
}
})
})
有人对解决这种情况的最佳方法有看法吗?
谢谢!
【问题讨论】:
-
真正的问题是什么?