我正在使用 Sequelize,但无法记录 promise 的值(value)。我正在做 console.log('helooo', timekeep);
但它打印 Promise { <pending> }
。我不知道我做得对不对。
这是我的代码:
const create = async function(req, res) {
res.setHeader('Content-Type', 'application/json');
let err, orders, wallet;
let orders_info = req.body;
console.log('order_info : <<<<<< ' + JSON.stringify(orders_info));
var timekeep = Orders.findAndCountAll(
{
where: {
cid : orders_info.cid,
},
order: [
['id', 'DESC']
],
limit: 1,
}
)
.then(result => {
console.log('hello', result);
console.log(result.count);
console.log(result.rows);
});
console.log('helooo', timekeep);
}
当我记录 var 时,我会变成这样。
helooo
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
最佳答案
timekeep
是您从 then
子句返回的值,即 Promise<void>
,因为它没有返回任何值。
您使用 result
打印的 console.log('hello', result);
具有您想要的 Promise 值。
关于mysql - 如何控制台记录 promise Sequelize 的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55566917/