我对koa2中两种不同的写作方式感到困惑。我的需求是
从mysql中获取两个结果,并将它们传递给ejs。
第一种方式
await mysqlModel.getThePeopleCount() //data from table `people`
.then(async(result) => {
let countpeople = result[0].peoplecount
await mysqlModel.getTheMyInfo() //data from table `myinfo`
.then(async(result) => {
await ctx.render('people', {
myinfo: result[0].name,
countpeoples:countpeople
});
})
})第二种方式
let results1 = await mysqlModel.getThePeopleCount()
let results2 = await mysqlModel.getTheMyInfo()
await ctx.render('people', {
myinfo: result2[0].name,
countpeoples:result1[0].peoplecount
});数据库是mysql的,哪一种是合理的方式?非常感谢。
https://stackoverflow.com/questions/51291739
复制相似问题