Skip to content

Commit c27d8b2

Browse files
authored
Merge pull request #2459 from appwrite/docs-transaction-api
Add transactions API docs
2 parents ece5edc + 22a59e4 commit c27d8b2

File tree

5 files changed

+1724
-6
lines changed

5 files changed

+1724
-6
lines changed

src/routes/docs/products/databases/+layout.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
label: 'Pagination',
7878
href: '/docs/products/databases/pagination'
7979
},
80+
{
81+
label: 'Transactions',
82+
href: '/docs/products/databases/transactions',
83+
new: isNewUntil('31 Oct 2025')
84+
},
8085
{
8186
label: 'Type generation',
8287
href: '/docs/products/databases/type-generation',

src/routes/docs/products/databases/atomic-numeric-operations/+page.markdoc

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,192 @@ update_result = tablesDB.update_row(
572572
```
573573
{% /multicode %}
574574

575+
# Use transactions {% #use-transactions %}
576+
577+
Atomic numeric operations accept `transactionId`. When provided, increments/decrements are staged and applied on commit.
578+
579+
{% multicode %}
580+
```client-web
581+
await tablesDB.incrementRowColumn({
582+
databaseId: '<DATABASE_ID>',
583+
tableId: '<TABLE_ID>',
584+
rowId: '<ROW_ID>',
585+
column: 'likes',
586+
value: 1,
587+
transactionId: '<TRANSACTION_ID>'
588+
});
589+
```
590+
```client-flutter
591+
await tablesDB.incrementRowColumn(
592+
databaseId: '<DATABASE_ID>',
593+
tableId: '<TABLE_ID>',
594+
rowId: '<ROW_ID>',
595+
column: 'likes',
596+
value: 1,
597+
transactionId: '<TRANSACTION_ID>'
598+
);
599+
```
600+
```client-apple
601+
try await tablesDB.incrementRowColumn(
602+
databaseId: "<DATABASE_ID>",
603+
tableId: "<TABLE_ID>",
604+
rowId: "<ROW_ID>",
605+
column: "likes",
606+
value: 1,
607+
transactionId: "<TRANSACTION_ID>"
608+
)
609+
```
610+
```client-android-kotlin
611+
tablesDB.incrementRowColumn(
612+
databaseId = "<DATABASE_ID>",
613+
tableId = "<TABLE_ID>",
614+
rowId = "<ROW_ID>",
615+
column = "likes",
616+
value = 1,
617+
transactionId = "<TRANSACTION_ID>"
618+
)
619+
```
620+
```client-android-java
621+
tablesDB.incrementRowColumn(
622+
"<DATABASE_ID>",
623+
"<TABLE_ID>",
624+
"<ROW_ID>",
625+
"likes",
626+
1,
627+
"<TRANSACTION_ID>",
628+
new CoroutineCallback<>((result, error) -> {
629+
if (error != null) {
630+
error.printStackTrace();
631+
return null;
632+
}
633+
System.out.println(result);
634+
return null;
635+
})
636+
);
637+
```
638+
```client-react-native
639+
await tablesDB.incrementRowColumn({
640+
databaseId: '<DATABASE_ID>',
641+
tableId: '<TABLE_ID>',
642+
rowId: '<ROW_ID>',
643+
column: 'likes',
644+
value: 1,
645+
transactionId: '<TRANSACTION_ID>'
646+
});
647+
```
648+
```server-nodejs
649+
await tablesDB.incrementRowColumn({
650+
databaseId: '<DATABASE_ID>',
651+
tableId: '<TABLE_ID>',
652+
rowId: '<ROW_ID>',
653+
column: 'likes',
654+
value: 1,
655+
transactionId: '<TRANSACTION_ID>'
656+
});
657+
```
658+
```server-deno
659+
await tablesDB.incrementRowColumn({
660+
databaseId: '<DATABASE_ID>',
661+
tableId: '<TABLE_ID>',
662+
rowId: '<ROW_ID>',
663+
column: 'likes',
664+
value: 1,
665+
transactionId: '<TRANSACTION_ID>'
666+
});
667+
```
668+
```server-python
669+
tablesDB.increment_row_column(
670+
database_id = '<DATABASE_ID>',
671+
table_id = '<TABLE_ID>',
672+
row_id = '<ROW_ID>',
673+
column = 'likes',
674+
value = 1,
675+
transaction_id = '<TRANSACTION_ID>'
676+
)
677+
```
678+
```server-php
679+
$tablesDB->incrementRowColumn(
680+
databaseId: '<DATABASE_ID>',
681+
tableId: '<TABLE_ID>',
682+
rowId: '<ROW_ID>',
683+
column: 'likes',
684+
value: 1,
685+
transactionId: '<TRANSACTION_ID>'
686+
);
687+
```
688+
```server-ruby
689+
tablesDB.increment_row_column(
690+
database_id: '<DATABASE_ID>',
691+
table_id: '<TABLE_ID>',
692+
row_id: '<ROW_ID>',
693+
column: 'likes',
694+
value: 1,
695+
transaction_id: '<TRANSACTION_ID>'
696+
)
697+
```
698+
```server-dotnet
699+
await tablesDB.IncrementRowColumn(
700+
databaseId: "<DATABASE_ID>",
701+
tableId: "<TABLE_ID>",
702+
rowId: "<ROW_ID>",
703+
column: "likes",
704+
value: 1,
705+
transactionId: "<TRANSACTION_ID>"
706+
);
707+
```
708+
```server-dart
709+
await tablesDB.incrementRowColumn(
710+
databaseId: '<DATABASE_ID>',
711+
tableId: '<TABLE_ID>',
712+
rowId: '<ROW_ID>',
713+
column: 'likes',
714+
value: 1,
715+
transactionId: '<TRANSACTION_ID>'
716+
);
717+
```
718+
```server-swift
719+
try await tablesDB.incrementRowColumn(
720+
databaseId: "<DATABASE_ID>",
721+
tableId: "<TABLE_ID>",
722+
rowId: "<ROW_ID>",
723+
column: "likes",
724+
value: 1,
725+
transactionId: "<TRANSACTION_ID>"
726+
)
727+
```
728+
```server-kotlin
729+
tablesDB.incrementRowColumn(
730+
databaseId = "<DATABASE_ID>",
731+
tableId = "<TABLE_ID>",
732+
rowId = "<ROW_ID>",
733+
column = "likes",
734+
value = 1,
735+
transactionId = "<TRANSACTION_ID>"
736+
)
737+
```
738+
```server-java
739+
tablesDB.incrementRowColumn(
740+
"<DATABASE_ID>",
741+
"<TABLE_ID>",
742+
"<ROW_ID>",
743+
"likes",
744+
1,
745+
"<TRANSACTION_ID>",
746+
new CoroutineCallback<>((result, error) -> {
747+
if (error != null) {
748+
error.printStackTrace();
749+
return null;
750+
}
751+
System.out.println(result);
752+
return null;
753+
})
754+
);
755+
```
756+
{% /multicode %}
757+
575758
## Explore related features
576759

577760
- [Bulk operations](/docs/products/databases/bulk-operations) - Update multiple rows at once
578761
- [Permissions](/docs/products/databases/permissions) - Control access to rows
579762
- [Queries](/docs/products/databases/queries) - Find rows to update
580-
- [Relationships](/docs/products/databases/relationships) - Update related rows
763+
- [Relationships](/docs/products/databases/relationships) - Update related rows

src/routes/docs/products/databases/bulk-operations/+page.markdoc

Lines changed: 145 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ const result = await tablesDB.createRows(
4646
[
4747
{
4848
$id: sdk.ID.unique(),
49-
data: { name: 'Row 1' }
49+
name: 'Row 1'
5050
},
5151
{
5252
$id: sdk.ID.unique(),
53-
data: { name: 'Row 2' }
53+
name: 'Row 2'
5454
}
5555
]
5656
);
@@ -73,11 +73,11 @@ result = tablesDB.create_rows(
7373
rows = [
7474
{
7575
'$id': appwrite.ID.unique(),
76-
'data': { 'name': 'Row 1' }
76+
'name': 'Row 1'
7777
},
7878
{
7979
'$id': appwrite.ID.unique(),
80-
'data': { 'name': 'Row 2' }
80+
'name': 'Row 2'
8181
}
8282
]
8383
)
@@ -262,4 +262,144 @@ When deleting rows, you must specify queries to filter which rows to delete.
262262
If no queries are provided, all rows in the table will be deleted.
263263
[Learn more about queries](/docs/products/databases/queries).
264264

265-
{% /info %}
265+
{% /info %}
266+
267+
# Use transactions {% #use-transactions %}
268+
269+
All bulk operations accept `transactionId`. When provided, Appwrite stages the bulk request and applies it on commit. See [Transactions](/docs/products/databases/transactions).
270+
271+
{% multicode %}
272+
```server-nodejs
273+
await tablesDB.createRows({
274+
databaseId: '<DATABASE_ID>',
275+
tableId: '<TABLE_ID>',
276+
rows: [
277+
{ $id: sdk.ID.unique(), name: 'One' },
278+
{ $id: sdk.ID.unique(), name: 'Two' }
279+
],
280+
transactionId: '<TRANSACTION_ID>'
281+
});
282+
```
283+
```server-python
284+
tablesDB.create_rows(
285+
database_id = '<DATABASE_ID>',
286+
table_id = '<TABLE_ID>',
287+
rows = [
288+
{ '$id': appwrite.ID.unique(), 'name': 'One' },
289+
{ '$id': appwrite.ID.unique(), 'name': 'Two' }
290+
],
291+
transaction_id = '<TRANSACTION_ID>'
292+
)
293+
```
294+
```server-deno
295+
await tablesDB.createRows({
296+
databaseId: '<DATABASE_ID>',
297+
tableId: '<TABLE_ID>',
298+
rows: [
299+
{ $id: sdk.ID.unique(), name: 'One' },
300+
{ $id: sdk.ID.unique(), name: 'Two' }
301+
],
302+
transactionId: '<TRANSACTION_ID>'
303+
});
304+
```
305+
```server-php
306+
$tablesDB->createRows(
307+
databaseId: '<DATABASE_ID>',
308+
tableId: '<TABLE_ID>',
309+
rows: [
310+
[ '$id' => ID::unique(), 'name' => 'One' ],
311+
[ '$id' => ID::unique(), 'name' => 'Two' ]
312+
],
313+
transactionId: '<TRANSACTION_ID>'
314+
);
315+
```
316+
```server-ruby
317+
tablesDB.create_rows(
318+
database_id: '<DATABASE_ID>',
319+
table_id: '<TABLE_ID>',
320+
rows: [
321+
{ '$id' => ID.unique(), 'name' => 'One' },
322+
{ '$id' => ID.unique(), 'name' => 'Two' }
323+
],
324+
transaction_id: '<TRANSACTION_ID>'
325+
)
326+
```
327+
```server-dotnet
328+
await tablesDB.CreateRows(
329+
databaseId: "<DATABASE_ID>",
330+
tableId: "<TABLE_ID>",
331+
rows: new List<Dictionary<string, object>>
332+
{
333+
new Dictionary<string, object>
334+
{
335+
["$id"] = ID.Unique(),
336+
["name"] = "One"
337+
},
338+
new Dictionary<string, object>
339+
{
340+
["$id"] = ID.Unique(),
341+
["name"] = "Two"
342+
}
343+
},
344+
transactionId: "<TRANSACTION_ID>"
345+
);
346+
```
347+
```server-dart
348+
await tablesDB.createRows(
349+
databaseId: '<DATABASE_ID>',
350+
tableId: '<TABLE_ID>',
351+
rows: [
352+
{ '\$id': ID.unique(), 'name': 'One' },
353+
{ '\$id': ID.unique(), 'name': 'Two' }
354+
],
355+
transactionId: '<TRANSACTION_ID>'
356+
);
357+
```
358+
```server-swift
359+
try await tablesDB.createRows(
360+
databaseId: "<DATABASE_ID>",
361+
tableId: "<TABLE_ID>",
362+
rows: [
363+
["$id": ID.unique(), "name": "One"],
364+
["$id": ID.unique(), "name": "Two"]
365+
],
366+
transactionId: "<TRANSACTION_ID>"
367+
)
368+
```
369+
```server-kotlin
370+
tablesDB.createRows(
371+
databaseId = "<DATABASE_ID>",
372+
tableId = "<TABLE_ID>",
373+
rows = listOf(
374+
mapOf("\$id" to ID.unique(), "name" to "One"),
375+
mapOf("\$id" to ID.unique(), "name" to "Two")
376+
),
377+
transactionId = "<TRANSACTION_ID>"
378+
)
379+
```
380+
```server-java
381+
tablesDB.createRows(
382+
"<DATABASE_ID>",
383+
"<TABLE_ID>",
384+
Arrays.asList(
385+
Map.of(
386+
"$id", ID.unique(),
387+
"name", "One"
388+
),
389+
Map.of(
390+
"$id", ID.unique(),
391+
"name", "Two"
392+
)
393+
),
394+
"<TRANSACTION_ID>",
395+
new CoroutineCallback<>((result, error) -> {
396+
if (error != null) {
397+
error.printStackTrace();
398+
return null;
399+
}
400+
System.out.println(result);
401+
return null;
402+
})
403+
);
404+
```
405+
{% /multicode %}

0 commit comments

Comments
 (0)