Skip to content

Commit dfb73b7

Browse files
committed
Add transactions
1 parent cd9336a commit dfb73b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1220
-54
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 17.4.0
4+
5+
* Add transaction support for Databases and TablesDB
6+
37
## 17.3.0
48

59
* Deprecate `createVerification` method in `Account` service

docs/databases.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,87 @@ POST https://cloud.appwrite.io/v1/databases
3131
| enabled | boolean | Is the database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled. | 1 |
3232

3333

34+
```http request
35+
GET https://cloud.appwrite.io/v1/databases/transactions
36+
```
37+
38+
** List transactions across all databases. **
39+
40+
### Parameters
41+
42+
| Field Name | Type | Description | Default |
43+
| --- | --- | --- | --- |
44+
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). | [] |
45+
46+
47+
```http request
48+
POST https://cloud.appwrite.io/v1/databases/transactions
49+
```
50+
51+
** Create a new transaction. **
52+
53+
### Parameters
54+
55+
| Field Name | Type | Description | Default |
56+
| --- | --- | --- | --- |
57+
| ttl | integer | Seconds before the transaction expires. | 300 |
58+
59+
60+
```http request
61+
GET https://cloud.appwrite.io/v1/databases/transactions/{transactionId}
62+
```
63+
64+
** Get a transaction by its unique ID. **
65+
66+
### Parameters
67+
68+
| Field Name | Type | Description | Default |
69+
| --- | --- | --- | --- |
70+
| transactionId | string | **Required** Transaction ID. | |
71+
72+
73+
```http request
74+
PATCH https://cloud.appwrite.io/v1/databases/transactions/{transactionId}
75+
```
76+
77+
** Update a transaction, to either commit or roll back its operations. **
78+
79+
### Parameters
80+
81+
| Field Name | Type | Description | Default |
82+
| --- | --- | --- | --- |
83+
| transactionId | string | **Required** Transaction ID. | |
84+
| commit | boolean | Commit transaction? | |
85+
| rollback | boolean | Rollback transaction? | |
86+
87+
88+
```http request
89+
DELETE https://cloud.appwrite.io/v1/databases/transactions/{transactionId}
90+
```
91+
92+
** Delete a transaction by its unique ID. **
93+
94+
### Parameters
95+
96+
| Field Name | Type | Description | Default |
97+
| --- | --- | --- | --- |
98+
| transactionId | string | **Required** Transaction ID. | |
99+
100+
101+
```http request
102+
POST https://cloud.appwrite.io/v1/databases/transactions/{transactionId}/operations
103+
```
104+
105+
** Create multiple operations in a single transaction. **
106+
107+
### Parameters
108+
109+
| Field Name | Type | Description | Default |
110+
| --- | --- | --- | --- |
111+
| transactionId | string | **Required** Transaction ID. | |
112+
| operations | array | Array of staged operations. | [] |
113+
114+
34115
```http request
35116
GET https://cloud.appwrite.io/v1/databases/{databaseId}
36117
```
@@ -705,6 +786,7 @@ GET https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI
705786
| databaseId | string | **Required** Database ID. | |
706787
| collectionId | string | **Required** Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). | |
707788
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] |
789+
| transactionId | string | Transaction ID to read uncommitted changes within the transaction. | |
708790

709791

710792
```http request
@@ -722,6 +804,7 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collection
722804
| documentId | string | Document ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. | |
723805
| data | object | Document data as JSON object. | {} |
724806
| permissions | array | An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). | |
807+
| transactionId | string | Transaction ID for staging the operation. | |
725808

726809

727810
```http request
@@ -737,6 +820,7 @@ POST https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collection
737820
| databaseId | string | **Required** Database ID. | |
738821
| collectionId | string | **Required** Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents. | |
739822
| documents | array | Array of documents data as JSON objects. | [] |
823+
| transactionId | string | Transaction ID for staging the operation. | |
740824

741825

742826
```http request
@@ -753,6 +837,7 @@ PUT https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI
753837
| databaseId | string | **Required** Database ID. | |
754838
| collectionId | string | **Required** Collection ID. | |
755839
| documents | array | Array of document data as JSON objects. May contain partial documents. | |
840+
| transactionId | string | Transaction ID for staging the operation. | |
756841

757842

758843
```http request
@@ -769,6 +854,7 @@ PATCH https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectio
769854
| collectionId | string | **Required** Collection ID. | |
770855
| data | object | Document data as JSON object. Include only attribute and value pairs to be updated. | {} |
771856
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] |
857+
| transactionId | string | Transaction ID for staging the operation. | |
772858

773859

774860
```http request
@@ -784,6 +870,7 @@ DELETE https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collecti
784870
| databaseId | string | **Required** Database ID. | |
785871
| collectionId | string | **Required** Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). | |
786872
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] |
873+
| transactionId | string | Transaction ID for staging the operation. | |
787874

788875

789876
```http request
@@ -800,6 +887,7 @@ GET https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI
800887
| collectionId | string | **Required** Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). | |
801888
| documentId | string | **Required** Document ID. | |
802889
| queries | array | Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. | [] |
890+
| transactionId | string | Transaction ID to read uncommitted changes within the transaction. | |
803891

804892

805893
```http request
@@ -817,6 +905,7 @@ PUT https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionI
817905
| documentId | string | **Required** Document ID. | |
818906
| data | object | Document data as JSON object. Include all required attributes of the document to be created or updated. | {} |
819907
| permissions | array | An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). | |
908+
| transactionId | string | Transaction ID for staging the operation. | |
820909

821910

822911
```http request
@@ -834,6 +923,7 @@ PATCH https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectio
834923
| documentId | string | **Required** Document ID. | |
835924
| data | object | Document data as JSON object. Include only attribute and value pairs to be updated. | {} |
836925
| permissions | array | An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions). | |
926+
| transactionId | string | Transaction ID for staging the operation. | |
837927

838928

839929
```http request
@@ -849,6 +939,7 @@ DELETE https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collecti
849939
| databaseId | string | **Required** Database ID. | |
850940
| collectionId | string | **Required** Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). | |
851941
| documentId | string | **Required** Document ID. | |
942+
| transactionId | string | Transaction ID for staging the operation. | |
852943

853944

854945
```http request
@@ -867,6 +958,7 @@ PATCH https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectio
867958
| attribute | string | **Required** Attribute key. | |
868959
| value | number | Value to increment the attribute by. The value must be a number. | 1 |
869960
| min | number | Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown. | |
961+
| transactionId | string | Transaction ID for staging the operation. | |
870962

871963

872964
```http request
@@ -885,6 +977,7 @@ PATCH https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectio
885977
| attribute | string | **Required** Attribute key. | |
886978
| value | number | Value to increment the attribute by. The value must be a number. | 1 |
887979
| max | number | Maximum value for the attribute. If the current value is greater than this value, an error will be thrown. | |
980+
| transactionId | string | Transaction ID for staging the operation. | |
888981

889982

890983
```http request
@@ -926,7 +1019,7 @@ Attributes can be `key`, `fulltext`, and `unique`. **
9261019
GET https://cloud.appwrite.io/v1/databases/{databaseId}/collections/{collectionId}/indexes/{key}
9271020
```
9281021

929-
** Get index by ID. **
1022+
** Get an index by its unique ID. **
9301023

9311024
### Parameters
9321025

docs/examples/databases/create-document.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ $result = $databases->createDocument(
2121
'age' => 30,
2222
'isAdmin' => false
2323
],
24-
permissions: ["read("any")"] // optional
24+
permissions: ["read("any")"], // optional
25+
transactionId: '<TRANSACTION_ID>' // optional
2526
);

docs/examples/databases/create-documents.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ $databases = new Databases($client);
1313
$result = $databases->createDocuments(
1414
databaseId: '<DATABASE_ID>',
1515
collectionId: '<COLLECTION_ID>',
16-
documents: []
16+
documents: [],
17+
transactionId: '<TRANSACTION_ID>' // optional
1718
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Databases;
5+
6+
$client = (new Client())
7+
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
8+
->setProject('<YOUR_PROJECT_ID>') // Your project ID
9+
->setKey('<YOUR_API_KEY>'); // Your secret API key
10+
11+
$databases = new Databases($client);
12+
13+
$result = $databases->createOperations(
14+
transactionId: '<TRANSACTION_ID>',
15+
operations: [
16+
{
17+
"action": "create",
18+
"databaseId": "<DATABASE_ID>",
19+
"collectionId": "<COLLECTION_ID>",
20+
"documentId": "<DOCUMENT_ID>",
21+
"data": {
22+
"name": "Walter O'Brien"
23+
}
24+
}
25+
] // optional
26+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Databases;
5+
6+
$client = (new Client())
7+
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
8+
->setProject('<YOUR_PROJECT_ID>') // Your project ID
9+
->setKey('<YOUR_API_KEY>'); // Your secret API key
10+
11+
$databases = new Databases($client);
12+
13+
$result = $databases->createTransaction(
14+
ttl: 60 // optional
15+
);

docs/examples/databases/decrement-document-attribute.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ $result = $databases->decrementDocumentAttribute(
1616
documentId: '<DOCUMENT_ID>',
1717
attribute: '',
1818
value: null, // optional
19-
min: null // optional
19+
min: null, // optional
20+
transactionId: '<TRANSACTION_ID>' // optional
2021
);

docs/examples/databases/delete-document.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ $databases = new Databases($client);
1313
$result = $databases->deleteDocument(
1414
databaseId: '<DATABASE_ID>',
1515
collectionId: '<COLLECTION_ID>',
16-
documentId: '<DOCUMENT_ID>'
16+
documentId: '<DOCUMENT_ID>',
17+
transactionId: '<TRANSACTION_ID>' // optional
1718
);

docs/examples/databases/delete-documents.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ $databases = new Databases($client);
1313
$result = $databases->deleteDocuments(
1414
databaseId: '<DATABASE_ID>',
1515
collectionId: '<COLLECTION_ID>',
16-
queries: [] // optional
16+
queries: [], // optional
17+
transactionId: '<TRANSACTION_ID>' // optional
1718
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Appwrite\Client;
4+
use Appwrite\Services\Databases;
5+
6+
$client = (new Client())
7+
->setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
8+
->setProject('<YOUR_PROJECT_ID>') // Your project ID
9+
->setKey('<YOUR_API_KEY>'); // Your secret API key
10+
11+
$databases = new Databases($client);
12+
13+
$result = $databases->deleteTransaction(
14+
transactionId: '<TRANSACTION_ID>'
15+
);

0 commit comments

Comments
 (0)