@@ -52,3 +52,50 @@ More info can be found in [here](https://docs.sqlc.dev/en/stable/reference/query
5252| sqlc.embed | ✅ | ✅ | ✅ |
5353
5454More info can be found in [ here] ( https://docs.sqlc.dev/en/stable/reference/macros.html#macros ) .
55+
56+
57+ ### Transactions
58+ Transactions are supported by the plugin.
59+ <br />
60+
61+ | Feature | PostgresSQL | MySQL | SQLite |
62+ | -------------| -------------| -------| ---------|
63+ | Transactions| ✅ | ✅ | ✅ |
64+
65+ #### Example using a transaction
66+ ``` c#
67+ public async Task ExampleTransaction (IDbConnection connection )
68+ {
69+ // Begin a transaction
70+ using (var transaction = connection .BeginTransaction ())
71+ {
72+ try
73+ {
74+ // Create a new Queries object with the transaction instead of the connection
75+ var queries = new QuerySql (transaction );
76+
77+ // Example: Insert a new author
78+ var newAuthor = await queries .CreateAuthor (new CreateAuthorParams { Name = " Jane Doe" , Bio = " Another author" });
79+
80+ // Example: Get the author by ID within the same transaction
81+ var author = await queries .GetAuthor (newAuthor .AuthorID );
82+
83+ // Example: Update the author's bio
84+ await queries .UpdateAuthorBio (new UpdateAuthorBioParams { AuthorID = author .AuthorID , Bio = " Updated bio for Jane Doe" });
85+
86+ // Commit the transaction if all operations are successful
87+ transaction .Commit ();
88+ Console .WriteLine (" Transaction committed successfully." );
89+ }
90+ catch (Exception ex )
91+ {
92+ // Rollback the transaction if any error occurs
93+ transaction .Rollback ();
94+ Console .WriteLine ($" Transaction rolled back due to error: {ex .Message }" );
95+ throw ;
96+ }
97+ }
98+ }
99+ ```
100+
101+ More info can be found in [ here] ( https://docs.sqlc.dev/en/stable/howto/transactions.html ) .
0 commit comments