如何获得knex / mysql中所有更新logging的列表

这是我正在处理的查询:

return knex('table') .returning('id') .where('boolean', false) .andWhere('fooID', foo.id) .update({ boolean : true }) .limit(num) .then(function(ids) { console.log('\nids'); console.log(ids); //outputs num 

ids现在包含3,这是受影响的行数。 有没有办法获得这3行的ID? 我是在印象.returning()做到了,但似乎没有。

Mysql数据库不支持returning语句,只返回更新行的数目http://dev.mysql.com/doc/refman/5.7/en/update.html

在你的情况下,你必须先查询要更新的行的id,然后在事务内部更新和获取它们。

喜欢这个:

 return knex.transaction(trx => { return trx('table') .select('id') .where('boolean', false) .andWhere('fooID', foo.id) .limit(num) .then(ids => { return trx('table').update({ boolean: true }) .whereIn('id', ids) .then(() => { return trx('table').whereIn('id', ids); }); }); });