私はknexjs
でレコードを挿入しますが、すぐに古いレコードを返します。どうして?挿入関数と選択関数の間の遅延をtimeout()に設定すると、正しいレコードが返されます。knexjsなぜmysqlが正しいレコードを返したのですか?
function(cb) { //callUser plan
sd = moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
ed = moment(new Date()).add(31, 'days').format("YYYY-MM-DD HH:mm:ss");
space = planDetail.space * 1024 * 1024 * 1024;
knex('user_plan')
.insert({
'username': userDetail.username,
'plan_id': planDetail.id,
'created': knex.raw('NOW()'),
'start_date': sd,
'end_date': ed,
'transaction_id': tran.id,
'space': space,
'slot': planDetail.slot
})
.asCallback(cb);
},
function(res, cb) {
logger.log(res);
return cb(null);
},
function(cb) {
knex.select('*').from('user_plan').where({
username: self.username,
})
.andWhere('start_date', '<', knex.raw('NOW()'))
.andWhere('end_date', '>', knex.raw('NOW()'))
.orderBy('id', 'desc')
.asCallback(function(err, rows) {
if(err) return cb(err);
logger.log(rows);
});
},
あなたの機能の実行順序を指定してください。 – RaghavGarg
あなたは 'async.js'を使っていることをタグで示していますが、使用している方法(パラレル、シリーズなど)を省いてしまいました。これは問題かもしれません。質問を編集して完全なコードを入力してください。 –