异步 where 子句
Async where clause
我将 knex 0.14.2 与 Node 8 一起使用,并且正在使用 async/await 语句。但我发现我需要根据请求构建一个 where
子句的情况:我构建我的主查询,执行 select
并向主查询添加一个 where
,具体取决于在结果上。所以我尝试了
mainQuery.where(async function() {
const res = await knex('table').select();
if(res.x) this.where('y', 'x');
})
但是在跟踪查询时,我看到主要的查询没有 where 子句,select 在它之后执行。
我想 await
没有得到很好的支持,但是有没有正确的方法来做这样的事情?
谢谢
怎么样:
const res = await knex('table').select();
await mainQuery.where(function() {
if(res.x) this.where('y', 'x');
})
Knex 永远不会支持异步解析内部构建器方法回调(换句话说,它不会支持 return 承诺的回调函数)。
我将 knex 0.14.2 与 Node 8 一起使用,并且正在使用 async/await 语句。但我发现我需要根据请求构建一个 where
子句的情况:我构建我的主查询,执行 select
并向主查询添加一个 where
,具体取决于在结果上。所以我尝试了
mainQuery.where(async function() {
const res = await knex('table').select();
if(res.x) this.where('y', 'x');
})
但是在跟踪查询时,我看到主要的查询没有 where 子句,select 在它之后执行。
我想 await
没有得到很好的支持,但是有没有正确的方法来做这样的事情?
谢谢
怎么样:
const res = await knex('table').select();
await mainQuery.where(function() {
if(res.x) this.where('y', 'x');
})
Knex 永远不会支持异步解析内部构建器方法回调(换句话说,它不会支持 return 承诺的回调函数)。