【发布时间】:2018-11-16 15:59:32
【问题描述】:
我有一个 knex QueryBuilder 对象qb,其中包含许多where 子句。我希望能够将整个 where 子句包装在一个 not 语句中,从而有效地否定整个 where 子句。
例子:
const qb = knex.queryBuilder();
qb.whereIn('name', ['alice', 'bob']);
// ... in some other part of the file ...
// Example of what I would like to do, effectively negate the above query if
// some condition is met.
if (negateSearch) {
const outerQb = knex.queryBuilder();
outerQb.whereNot(qb);
// execute outerQb
} else {
// execute qb
}
这应该会产生一个看起来像
的查询where not (name in ('alice', 'bob'))`
【问题讨论】:
标签: knex.js