Skip to content

Commit 01db552

Browse files
authored
Merge pull request #50 from appwrite/dev
Add inc/dec
2 parents 219f7c7 + 74e1138 commit 01db552

23 files changed

+522
-30
lines changed

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# Change Log
1+
# Change Log
2+
3+
## 9.1.0
4+
5+
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service
6+
* Add `dart38` and `flutter332` support to runtime models
7+
* Add `gif` support to `ImageFormat` enum
8+
* Add `encrypt` support to `StringAttribute` model
9+
* Add `sequence` support to `Document` model
10+
11+
## 9.0.0
12+
13+
* Add `<REGION>` to doc examples due to the new multi region endpoints
14+
* Add doc examples and methods for bulk api transactions: `createDocuments`, `deleteDocuments` etc.
15+
* Add doc examples, class and methods for new `Sites` service
16+
* Add doc examples, class and methods for new `Tokens` service
17+
* Add enums for `BuildRuntime `, `Adapter`, `Framework`, `DeploymentDownloadType` and `VCSDeploymentType`
18+
* Update enum for `runtimes` with Pythonml312, Dart219, Flutter327 and Flutter329
19+
* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
20+
* Add `queries` and `search` params to `listMemberships` method
21+
* Remove `search` param from `listExecutions` method
22+
23+
## 8.0.0
24+
25+
* Fix requests failing by removing `Content-Type` header from `GET` and `HEAD` requests
26+
27+
## 7.0.0
28+
29+
* Fix pong response & chunked upload

README.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-kotlin.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-kotlin.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

@@ -39,7 +39,7 @@ repositories {
3939
Next, add the dependency to your project's `build.gradle(.kts)` file:
4040

4141
```groovy
42-
implementation("io.appwrite:sdk-for-kotlin:9.0.0")
42+
implementation("io.appwrite:sdk-for-kotlin:9.1.0")
4343
```
4444

4545
### Maven
@@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file:
5050
<dependency>
5151
<groupId>io.appwrite</groupId>
5252
<artifactId>sdk-for-kotlin</artifactId>
53-
<version>9.0.0</version>
53+
<version>9.1.0</version>
5454
</dependency>
5555
</dependencies>
5656
```
@@ -115,6 +115,77 @@ suspend fun main() {
115115
}
116116
```
117117

118+
### Type Safety with Models
119+
120+
The Appwrite Kotlin SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a `nestedType` parameter that allows you to specify your custom model type for full type safety.
121+
122+
```kotlin
123+
data class Book(
124+
val name: String,
125+
val author: String,
126+
val releaseYear: String? = null,
127+
val category: String? = null,
128+
val genre: List<String>? = null,
129+
val isCheckedOut: Boolean
130+
)
131+
132+
val databases = Databases(client)
133+
134+
try {
135+
val documents = databases.listDocuments(
136+
databaseId = "your-database-id",
137+
collectionId = "your-collection-id",
138+
nestedType = Book::class.java // Pass in your custom model type
139+
)
140+
141+
for (book in documents.documents) {
142+
Log.d("Appwrite", "Book: ${book.name} by ${book.author}") // Now you have full type safety
143+
}
144+
} catch (e: AppwriteException) {
145+
Log.e("Appwrite", e.message ?: "Unknown error")
146+
}
147+
```
148+
149+
**Tip**: You can use the `appwrite types` command to automatically generate model definitions based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
150+
151+
### Working with Model Methods
152+
153+
All Appwrite models come with built-in methods for data conversion and manipulation:
154+
155+
**`toMap()`** - Converts a model instance to a Map format, useful for debugging or manual data manipulation:
156+
```kotlin
157+
val account = Account(client)
158+
val user = account.get()
159+
val userMap = user.toMap()
160+
Log.d("Appwrite", userMap.toString()) // Prints all user properties as a Map
161+
```
162+
163+
**`from(map:, nestedType:)`** - Creates a model instance from a Map, useful when working with raw data:
164+
```kotlin
165+
val userData: Map<String, Any> = mapOf(
166+
"\$id" to "123",
167+
"name" to "John",
168+
"email" to "[email protected]"
169+
)
170+
val user = User.from(userData, User::class.java)
171+
```
172+
173+
**JSON Serialization** - Models can be easily converted to/from JSON using Gson (which the SDK uses internally):
174+
```kotlin
175+
import com.google.gson.Gson
176+
177+
val account = Account(client)
178+
val user = account.get()
179+
180+
// Convert to JSON
181+
val gson = Gson()
182+
val jsonString = gson.toJson(user)
183+
Log.d("Appwrite", "User JSON: $jsonString")
184+
185+
// Convert from JSON
186+
val userFromJson = gson.fromJson(jsonString, User::class.java)
187+
```
188+
118189
### Error Handling
119190

120191
The Appwrite Kotlin SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.

docs/examples/java/databases/create-document.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import io.appwrite.services.Databases;
44

55
Client client = new Client()
66
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7-
.setSession("") // The user session to authenticate with
8-
.setKey("<YOUR_API_KEY>") // Your secret API key
9-
.setJWT("<YOUR_JWT>"); // Your secret JSON Web Token
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession(""); // The user session to authenticate with
109

1110
Databases databases = new Databases(client);
1211

docs/examples/java/databases/create-documents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.appwrite.services.Databases;
44

55
Client client = new Client()
66
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
78
.setKey("<YOUR_API_KEY>"); // Your secret API key
89

910
Databases databases = new Databases(client);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Databases;
4+
5+
Client client = new Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setKey("<YOUR_API_KEY>"); // Your secret API key
9+
10+
Databases databases = new Databases(client);
11+
12+
databases.decrementDocumentAttribute(
13+
"<DATABASE_ID>", // databaseId
14+
"<COLLECTION_ID>", // collectionId
15+
"<DOCUMENT_ID>", // documentId
16+
"", // attribute
17+
0, // value (optional)
18+
0, // min (optional)
19+
new CoroutineCallback<>((result, error) -> {
20+
if (error != null) {
21+
error.printStackTrace();
22+
return;
23+
}
24+
25+
System.out.println(result);
26+
})
27+
);
28+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Databases;
4+
5+
Client client = new Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setKey("<YOUR_API_KEY>"); // Your secret API key
9+
10+
Databases databases = new Databases(client);
11+
12+
databases.incrementDocumentAttribute(
13+
"<DATABASE_ID>", // databaseId
14+
"<COLLECTION_ID>", // collectionId
15+
"<DOCUMENT_ID>", // documentId
16+
"", // attribute
17+
0, // value (optional)
18+
0, // max (optional)
19+
new CoroutineCallback<>((result, error) -> {
20+
if (error != null) {
21+
error.printStackTrace();
22+
return;
23+
}
24+
25+
System.out.println(result);
26+
})
27+
);
28+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Databases;
4+
5+
Client client = new Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession(""); // The user session to authenticate with
9+
10+
Databases databases = new Databases(client);
11+
12+
databases.upsertDocument(
13+
"<DATABASE_ID>", // databaseId
14+
"<COLLECTION_ID>", // collectionId
15+
"<DOCUMENT_ID>", // documentId
16+
mapOf( "a" to "b" ), // data
17+
listOf("read("any")"), // permissions (optional)
18+
new CoroutineCallback<>((result, error) -> {
19+
if (error != null) {
20+
error.printStackTrace();
21+
return;
22+
}
23+
24+
System.out.println(result);
25+
})
26+
);
27+

docs/examples/java/databases/upsert-documents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Databases databases = new Databases(client);
1212
databases.upsertDocuments(
1313
"<DATABASE_ID>", // databaseId
1414
"<COLLECTION_ID>", // collectionId
15-
listOf(), // documents (optional)
15+
listOf(), // documents
1616
new CoroutineCallback<>((result, error) -> {
1717
if (error != null) {
1818
error.printStackTrace();

docs/examples/kotlin/databases/create-document.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import io.appwrite.services.Databases
44

55
val client = Client()
66
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
78
.setSession("") // The user session to authenticate with
8-
.setKey("<YOUR_API_KEY>") // Your secret API key
9-
.setJWT("<YOUR_JWT>") // Your secret JSON Web Token
109

1110
val databases = Databases(client)
1211

docs/examples/kotlin/databases/create-documents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.appwrite.services.Databases
44

55
val client = Client()
66
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
78
.setKey("<YOUR_API_KEY>") // Your secret API key
89

910
val databases = Databases(client)

0 commit comments

Comments
 (0)