.update(data, [returning]) / .update(key, value, [returning])

创建更新查询,并根据其他查询约束获取要更新的属性或键/值对的哈希。

如果传递了返回的数组,例如['id','title'],它将使用所有包含指定列的更新行的数组来解析promise /实现回调。

这是返回方法的快捷方式   

knex('books')
.where('published_date', '<', 2000)
.update({
status: 'archived',
thisKeyIsSkipped: undefined
});
输出:
update `books` set `status` = 'archived' where `published_date` < 2000

// Returns [1] in "mysql", "sqlite", "oracle"; [] in "postgresql" unless the 'returning' parameter is set.
knex('books').update('title', 'Slaughterhouse Five')

输出:
update `books` set `title` = 'Slaughterhouse Five'

// Returns [ { id: 42, title: "The Hitchhiker's Guide to the Galaxy" } ]
knex('books')
.where({ id: 42 })
.update({ title: "The Hitchhiker's Guide to the Galaxy" }, ['id', 'title'])
输出:
update `books` set `title` = 'The Hitchhiker\'s Guide to the Galaxy' where `id` = 42
删除/删除 -.del()

别名del作为delete是JavaScript中的保留字,此方法根据查询中指定的其他条件删除一个或多个行。通过查询受影响的行数来解决promise /完成回调。   

knex('accounts')
.where('activated', false)
.del();
输出:
delete from `accounts` where `activated` = false