使用Knex JS-是否可以从要更新的行中获取所有元素,我希望在单个查询中完成updateselect。 (当前update仅返回要更新的行的id)。

let query = await knex('items').select('id', 'customerId', 'itemId').where('id', id).update({ inactive: true })


谢谢!

最佳答案

如果使用postgres,请使用.returning()

const query: any = await knex('items')
  .returning('id', 'customerId', 'itemId')
  .where('id', id)
  .update({ inactive: true });


这是knex文档
https://knexjs.org/#Builder-returning

10-07 12:32
查看更多