-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lucid models and transactions #43
Comments
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. |
now model instance useTransaction method makes it easier to use transactions for database writes Closes #43
At first, thank you for AdonisJS.
Is it possible to save or update model instances using transactions?
The text was updated successfully, but these errors were encountered: