0
var userid = 7;
var um;
sequelize.query("select user_money from ecs_users u where u.user_id = ?", {replacements: [userid], type: sequelize.QueryTypes.SELECT}).then(function(data) {
console.log('Inside um is '+data[0].user_money);
um = data[0].user_money;
});
//how to get the result at here ???
console.log('Outside um is '+um);
console.log('testtesttest');
Outside um is undefined
testtesttest
info: Executing (default): select user_money from ecs_users u where u.user_id = 7
Inside um is 0.01
如何獲得的結果麼?
sequelize.query()不具有同步功能嗎? – dindinmail
同步功能將鎖定您的主線程。如果你從來沒有超過一個人同時使用你的應用程序,這可能是好的。但是,由於這不是典型的,因此很多Node.js庫都不會同時使用同步函數,因爲它們最終既危險又不必要。 – Trott