Node.js 在bookshelf.js中保存多条记录
如何在bookshelf.js中保存多条记录 如何在不循环和插入的情况下保存以下数据Node.js 在bookshelf.js中保存多条记录,node.js,bookshelf.js,Node.js,Bookshelf.js,如何在bookshelf.js中保存多条记录 如何在不循环和插入的情况下保存以下数据 [ {name: 'Person1'}, {name: 'Person2'} ] 请参见注释:Invoke现在已被invokeThen取代 accounts.invokeThen('save').then(function() { // ... all models in the collection have been saved }); 我想书架已经更新了,用invokeThen代替invo
[
{name: 'Person1'},
{name: 'Person2'}
]
请参见注释:Invoke现在已被invokeThen取代
accounts.invokeThen('save').then(function() {
// ... all models in the collection have been saved
});
我想书架已经更新了,用invokeThen代替invoke
var Accounts=bookshelf.Collection.extend({
型号:账户
});
var accounts=accounts.forge([
{name:'Person1'},
{name:'Person2'}
])
accounts.invoketen('save')。然后(function(){
//…集合中的所有模型都已保存
});代码>我尝试使用forge跟踪invoketen,但在我的案例中失败了。似乎我们可以使用模型本身,而不必创建单独的集合实例
Employee.collection()
.add(employees)
.invokeThen('save');
使用invokeThen方法中的第三个参数执行insert方法,如下所示
const payload = [{name: 'Person1'},
{name: 'Person2'}]
Users.collection(payload).invokeThen("save", null, { method: "insert" }).then(result => {
// further logics
})
我希望这有帮助
谢谢Think invoke已被invokeThen取代。这并不是一次就把它们全部保存下来。每次保存都会运行一个单独的数据库查询。@阿舍:如何在一个查询中保存所有记录?要在一个查询中保存多条记录,您应该使用bookshelf的knex实例并调用。insert([])
如何使用where子句更新bookshelf中的多行,它可以一次或逐个保存所有记录?
const payload = [{name: 'Person1'},
{name: 'Person2'}]
Users.collection(payload).invokeThen("save", null, { method: "insert" }).then(result => {
// further logics
})