这是原始查询,它正在工作 -
Insert into members (activity, emp_id, plan_id) VALUES ('admin', 21937, 2463) on conflict(emp_id, plan_id) where ("responsibility" != 'admin') DO Nothing;
将此查询转换为 knex 查询,但是当我打印由 knex 构建的查询时,它避免了 where 子句。
let result = knex('members').withSchema('public').insert(insertParameters);
result = result
.whereNotIn({
'member.responsibility': 'admin',
})
.onConflict(['emp_id', 'plan_id'])
.ignore();
result = await result.returning('id');
return result;
knex 准备的查询 -
insert into "public"."member" ("plan_id", "responsibility", "emp_id") values ($1, $2, $3), ($4, $5, $6), ($7, $8, $9) on conflict ("emp_id", "plan_id") do nothing returning "id"
为列 - 创建了一个索引emp_id, plan_id, and responsibility != 'admin'
,因此我们需要编写 where 子句。