Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- knex.transaction(function(trx) {
- var books = [
- {title: 'Canterbury Tales'},
- {title: 'Moby Dick'},
- {title: 'Hamlet'}
- ];
- return trx
- .insert({name: 'Old Books'}, 'id')
- .into('catalogues')
- .then(function(ids) {
- return Promise.map(books, function(book) {
- book.catalogue_id = ids[0];
- // Some validation could take place here.
- return trx.insert(info).into('books');
- });
- });
- })
- knex.transaction(function(trx) {
- knex('foo')
- .transacting(trx)
- .insert({id:"bar", username:"bar"})
- // etc
- })
Add Comment
Please, Sign In to add comment