Lucid models and transactions
At first, thank you for AdonisJS.
Is it possible to save or update model instances using transactions?
You can make use of transactions as defined here http://adonisjs.com/docs/3.0/query-builder#database-transactions when trying to fetch data via models.
For example
const Database = use('Database')
const trx = yield Database.beginTransaction()
const users = yield User.query().transacting(trx).fetch()
trx.commit()
But that is not the ideal use case, a normal web application makes use of transactions when trying to persist data.
For now there is no out of the box way to make use of transactions with models, but I believe it will be fairly simple to add that and final implementation may look like this.
const Database = use('Database')
const trx = yield Database.beginTransaction()
const user = new User()
user.username = 'liza'
user.password = 'secret'
user.useTransaction(trx)
yield user.save()
trx.commit()
You can also share your thoughts on same.
Agreed. Syntax is simple and readable. Can't wait to see it in release.