From 34da685b11c5d9b5c8633839119cb3e6a181f9c8 Mon Sep 17 00:00:00 2001 From: nathaelbonnal Date: Mon, 6 Jan 2025 14:53:35 +0100 Subject: [PATCH 1/2] feat: add transaction example with customer as a parameter --- content/docs/guides/transactions.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/content/docs/guides/transactions.md b/content/docs/guides/transactions.md index b49a861..983fb95 100644 --- a/content/docs/guides/transactions.md +++ b/content/docs/guides/transactions.md @@ -170,6 +170,21 @@ await db.transaction(async (trx) => { // highlight-end ``` +It is possible to give the transaction as a customer, here is a simple example. + +```ts +import User from '#models/user' +import db from '@adonisjs/lucid/services/db' + +// highlight-start +await db.transaction(async (trx) => { + const user = await User.create({ + username: 'virk' + }, { client: trx }) +}) +// highlight-end +``` + ### Model query builder Just like the standard query builder, you can also pass the transaction to the model query builder. From 725a50d4b10c9107d9ac10b1402732fb43059b57 Mon Sep 17 00:00:00 2001 From: nathaelbonnal Date: Mon, 20 Jan 2025 10:12:22 +0100 Subject: [PATCH 2/2] feat: update transaction example to use transaction as a parameter --- content/docs/guides/transactions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/guides/transactions.md b/content/docs/guides/transactions.md index 983fb95..63448eb 100644 --- a/content/docs/guides/transactions.md +++ b/content/docs/guides/transactions.md @@ -170,7 +170,7 @@ await db.transaction(async (trx) => { // highlight-end ``` -It is possible to give the transaction as a customer, here is a simple example. +Instead of instantiating your entity using the `new` keyword, you can give the transaction in the client as a parameter. ```ts import User from '#models/user'