如何获得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); }); }); });
- Promise Chain Breaks w / .all()
- 如何在Knexunit testing时模拟一个假数据库?
- Javascript – 将以前的查询结果传递到下一个.then()
- 如何连接,创build数据库,重新连接数据库,并在knex.js中创build表?
- 使用express-sessions和knex使所有用户会话无效
- Knex.js&MySQL:将整型转换为布尔值以进行批量select
- 将数组数据批量插入到使用objection.js的mysql数据库中
- 在当前客户端上没有定义池 – knex.js + node + postgresql
- Mysql方言不能在knex(browserified)