【发布时间】:2016-09-16 18:20:12
【问题描述】:
我想在所有更新查询完成后从box_property 中删除
我写了这段代码,但我不确定这是否正确。我想同步运行更新查询
var data = [1, 2, 3, 4]; //data generate dynamicly
for (var i = 0; i < BoxData.length; i++) {
pool.connect(function(err, client, done) {
client.query("update box set gamer_id=null where box_id=$1; ", [data[i]], function(err, resultUpdate) {
if ((i + 1) == BoxData.length) {
//when all query finished then run this query
client.query("delete from box_property where gamer_id=$1;", [gamer_id], function(err, resultUpdate) {})
}
})
})
}
有没有办法运行更新查询同步并在 for 循环之后运行删除查询?
喜欢这个
var data = [1, 2, 3, 4]; //data generate dynamicly
for (var i = 0; i < BoxData.length; i++) {
pool.connect(function(err, client, done) {
client.query("update box set gamer_id=null where box_id=$1; ", [data[i]], function(err, resultUpdate) {
})
})
}
//when all query finished then run this query
client.query("delete from box_property where gamer_id=$1;", [gamer_id], function(err, resultUpdate) {})
【问题讨论】:
标签: node.js postgresql