Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/routes/docs/products/databases/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
label: 'Pagination',
href: '/docs/products/databases/pagination'
},
{
label: 'Transactions',
href: '/docs/products/databases/transactions',
new: isNewUntil('31 Oct 2025')
},
{
label: 'Type generation',
href: '/docs/products/databases/type-generation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,192 @@ update_result = tablesDB.update_row(
```
{% /multicode %}

# Use transactions {% #use-transactions %}

Atomic numeric operations accept `transactionId`. When provided, increments/decrements are staged and applied on commit.

{% multicode %}
```client-web
await tablesDB.incrementRowColumn({
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
});
```
```client-flutter
await tablesDB.incrementRowColumn(
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
);
```
```client-apple
let _ = try await tablesDB.incrementRowColumn(
databaseId: "<DATABASE_ID>",
tableId: "<TABLE_ID>",
rowId: "<ROW_ID>",
column: "likes",
value: 1,
transactionId: "<TRANSACTION_ID>"
)
```
```client-android-kotlin
val _ = tablesDB.incrementRowColumn(
databaseId = "<DATABASE_ID>",
tableId = "<TABLE_ID>",
rowId = "<ROW_ID>",
column = "likes",
value = 1,
transactionId = "<TRANSACTION_ID>"
)
```
```client-android-java
tablesDB.incrementRowColumn(
"<DATABASE_ID>",
"<TABLE_ID>",
"<ROW_ID>",
"likes",
1,
"<TRANSACTION_ID>",
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return null;
}
System.out.println(result);
return null;
})
);
```
```client-react-native
await tablesDB.incrementRowColumn({
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
});
```
```server-nodejs
await tablesDB.incrementRowColumn({
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
});
```
```server-deno
await tablesDB.incrementRowColumn({
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
});
```
```server-python
tablesDB.increment_row_column(
database_id = '<DATABASE_ID>',
table_id = '<TABLE_ID>',
row_id = '<ROW_ID>',
column = 'likes',
value = 1,
transaction_id = '<TRANSACTION_ID>'
)
```
```server-php
$tablesDB->incrementRowColumn(
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
);
```
```server-ruby
tablesDB.increment_row_column(
database_id: '<DATABASE_ID>',
table_id: '<TABLE_ID>',
row_id: '<ROW_ID>',
column: 'likes',
value: 1,
transaction_id: '<TRANSACTION_ID>'
)
```
```server-dotnet
await tablesDB.IncrementRowColumn(
databaseId: "<DATABASE_ID>",
tableId: "<TABLE_ID>",
rowId: "<ROW_ID>",
column: "likes",
value: 1,
transactionId: "<TRANSACTION_ID>"
);
```
```server-dart
await tablesDB.incrementRowColumn(
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rowId: '<ROW_ID>',
column: 'likes',
value: 1,
transactionId: '<TRANSACTION_ID>'
);
```
```server-swift
let _ = try await tablesDB.incrementRowColumn(
databaseId: "<DATABASE_ID>",
tableId: "<TABLE_ID>",
rowId: "<ROW_ID>",
column: "likes",
value: 1,
transactionId: "<TRANSACTION_ID>"
)
```
```server-kotlin
val _ = tablesDB.incrementRowColumn(
databaseId = "<DATABASE_ID>",
tableId = "<TABLE_ID>",
rowId = "<ROW_ID>",
column = "likes",
value = 1,
transactionId = "<TRANSACTION_ID>"
)
```
```server-java
tablesDB.incrementRowColumn(
"<DATABASE_ID>",
"<TABLE_ID>",
"<ROW_ID>",
"likes",
1,
"<TRANSACTION_ID>",
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return null;
}
System.out.println(result);
return null;
})
);
```
{% /multicode %}

## Explore related features

- [Bulk operations](/docs/products/databases/bulk-operations) - Update multiple rows at once
- [Permissions](/docs/products/databases/permissions) - Control access to rows
- [Queries](/docs/products/databases/queries) - Find rows to update
- [Relationships](/docs/products/databases/relationships) - Update related rows
- [Relationships](/docs/products/databases/relationships) - Update related rows
129 changes: 128 additions & 1 deletion src/routes/docs/products/databases/bulk-operations/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,131 @@ When deleting rows, you must specify queries to filter which rows to delete.
If no queries are provided, all rows in the table will be deleted.
[Learn more about queries](/docs/products/databases/queries).

{% /info %}
{% /info %}

# Use transactions {% #use-transactions %}

All bulk operations accept `transactionId`. When provided, Appwrite stages the bulk request and applies it on commit. See [Transactions](/docs/products/databases/transactions).

{% multicode %}
```server-nodejs
await tablesDB.createRows('<DATABASE_ID>', '<TABLE_ID>', [
{ $id: sdk.ID.unique(), data: { name: 'One' } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data should not be nested here, table columns should be top level in the objects:

{ $id: sdk.ID.unique(), name: 'One' },

Applies to all bulk create examples across all changes

{ $id: sdk.ID.unique(), data: { name: 'Two' } }
], { transactionId: '<TRANSACTION_ID>' });
```
```server-python
tablesDB.update_rows(
database_id = '<DATABASE_ID>',
table_id = '<TABLE_ID>',
data = { 'status': 'published' },
queries = [ Query.equal('status', 'draft') ],
transaction_id = '<TRANSACTION_ID>'
)
```
```server-deno
await tablesDB.createRows('<DATABASE_ID>', '<TABLE_ID>', [
{ $id: sdk.ID.unique(), data: { name: 'One' } },
{ $id: sdk.ID.unique(), data: { name: 'Two' } }
], { transactionId: '<TRANSACTION_ID>' });
```
```server-php
$tablesDB->createRows(
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rows: [
[ '$id' => ID::unique(), 'data' => [ 'name' => 'One' ] ],
[ '$id' => ID::unique(), 'data' => [ 'name' => 'Two' ] ]
],
transactionId: '<TRANSACTION_ID>'
);
```
```server-ruby
tablesDB.create_rows(
database_id: '<DATABASE_ID>',
table_id: '<TABLE_ID>',
rows: [
{ '$id' => ID.unique(), 'data' => { 'name' => 'One' } },
{ '$id' => ID.unique(), 'data' => { 'name' => 'Two' } }
],
transaction_id: '<TRANSACTION_ID>'
)
```
```server-dotnet
await tablesDB.CreateRows(
databaseId: "<DATABASE_ID>",
tableId: "<TABLE_ID>",
rows: new List<Dictionary<string, object>>
{
new Dictionary<string, object>
{
["$id"] = ID.Unique(),
["data"] = new Dictionary<string, object> { ["name"] = "One" }
},
new Dictionary<string, object>
{
["$id"] = ID.Unique(),
["data"] = new Dictionary<string, object> { ["name"] = "Two" }
}
},
transactionId: "<TRANSACTION_ID>"
);
```
```server-dart
await tablesDB.createRows(
databaseId: '<DATABASE_ID>',
tableId: '<TABLE_ID>',
rows: [
{ '\$id': ID.unique(), 'data': { 'name': 'One' } },
{ '\$id': ID.unique(), 'data': { 'name': 'Two' } }
],
transactionId: '<TRANSACTION_ID>'
);
```
```server-swift
let _ = try await tablesDB.createRows(
databaseId: "<DATABASE_ID>",
tableId: "<TABLE_ID>",
rows: [
["$id": ID.unique(), "data": ["name": "One"]],
["$id": ID.unique(), "data": ["name": "Two"]]
],
transactionId: "<TRANSACTION_ID>"
)
```
```server-kotlin
val _ = tablesDB.createRows(
databaseId = "<DATABASE_ID>",
tableId = "<TABLE_ID>",
rows = listOf(
mapOf("\$id" to ID.unique(), "data" to mapOf("name" to "One")),
mapOf("\$id" to ID.unique(), "data" to mapOf("name" to "Two"))
),
transactionId = "<TRANSACTION_ID>"
)
```
```server-java
Map<String, Object> row1 = new HashMap<>();
row1.put("$id", ID.unique());
row1.put("data", new HashMap<String, Object>() {{ put("name", "One"); }});

Map<String, Object> row2 = new HashMap<>();
row2.put("$id", ID.unique());
row2.put("data", new HashMap<String, Object>() {{ put("name", "Two"); }});

tablesDB.createRows(
"<DATABASE_ID>",
"<TABLE_ID>",
Arrays.asList(row1, row2),
"<TRANSACTION_ID>",
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
return null;
}
System.out.println(result);
return null;
})
);
```
{% /multicode %}
Loading