Guest User

Untitled

a guest
Oct 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. knex.transaction(function(trx) {
  2. var books = [
  3. {title: 'Canterbury Tales'},
  4. {title: 'Moby Dick'},
  5. {title: 'Hamlet'}
  6. ];
  7.  
  8. return trx
  9. .insert({name: 'Old Books'}, 'id')
  10. .into('catalogues')
  11. .then(function(ids) {
  12. return Promise.map(books, function(book) {
  13. book.catalogue_id = ids[0];
  14.  
  15. // Some validation could take place here.
  16.  
  17. return trx.insert(info).into('books');
  18. });
  19. });
  20. })
  21.  
  22. knex.transaction(function(trx) {
  23. knex('foo')
  24. .transacting(trx)
  25. .insert({id:"bar", username:"bar"})
  26. // etc
  27. })
Add Comment
Please, Sign In to add comment