gpt4 book ai didi

mysql - 异步和 Knex : how they work ?

转载 作者:行者123 更新时间:2023-11-30 22:31:04 26 4
gpt4 key购买 nike

我解析一个 json 对象,对于每个元素,我需要执行许多查询。首先,“选择”查询并根据结果执行插入或更新。我想使用 async.js 和 knex.js问题是执行顺序不是搜索顺序

            async.each(newContent,function(e){
//var e=JSON.stringify(element),
var z=-1,
devicepresenceId = e.device_presence_id;
//console.log(e);
async.waterfall([
function(cb) {
knex('jos_joomrh_event_employee_hours_presence')
.whereRaw('device_presence_id=?', devicepresenceId)
.select('id', 'applied_at', 'applied_at_end')
.debug()
.then(function (rows) {
console.log(rows);
z = _.keys(rows).length;
console.log('rows0', z);
cb(null,z);
})
.catch(function (e) {
console.log(e)
reject(e)
})
cb(null,z);
},
function(z,cb){
console.log('z',z);
if (parseInt(z)==0)
{
console.log('insertHoursPresence');
//insertHoursPresence(e)
}
else{
console.log('updateHoursPresence');
//updateHoursPresence(e)
}
cb(null,'two')
}
],
function(err,z){
if(err)console.log(err);
console.log(z);
}
)}
)}

事实上;它执行第二个函数和 cb 函数,并在第一个函数之后用 knex 执行。:感谢您的帮助姆杜克

最佳答案

在 knex 部分,您调用了“cb(null,z)”,您必须“移动”调用内部 catch 函数(但替换 reject(e) 部分)。您的问题是您在 knex 外部调用 cb() 函数,当然它会立即独立于 knex 结果被调用)

关于mysql - 异步和 Knex : how they work ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com