mirror of
https://github.com/appwrite/sdk-for-android.git
synced 2026-04-07 19:17:49 +00:00
chore: add setDevKey and upsertDocument methods
This commit is contained in:
+8
-1
@@ -1 +1,8 @@
|
||||
# Change Log
|
||||
# Change Log
|
||||
|
||||
## 8.0.0
|
||||
|
||||
* Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
|
||||
* Update default `quality` for `getFilePreview` from 0 to -1
|
||||
* Remove `Gif` from ImageFormat enum
|
||||
* Remove `search` param from `listExecutions` method
|
||||
@@ -38,7 +38,7 @@ repositories {
|
||||
Next, add the dependency to your project's `build.gradle(.kts)` file:
|
||||
|
||||
```groovy
|
||||
implementation("io.appwrite:sdk-for-android:8.0.0")
|
||||
implementation("io.appwrite:sdk-for-android:8.0.1")
|
||||
```
|
||||
|
||||
### Maven
|
||||
@@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
|
||||
<dependency>
|
||||
<groupId>io.appwrite</groupId>
|
||||
<artifactId>sdk-for-android</artifactId>
|
||||
<version>8.0.0</version>
|
||||
<version>8.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import io.appwrite.Client;
|
||||
import io.appwrite.coroutines.CoroutineCallback;
|
||||
import io.appwrite.services.Databases;
|
||||
|
||||
Client client = new Client(context)
|
||||
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
|
||||
.setKey(""); //
|
||||
|
||||
Databases databases = new Databases(client);
|
||||
|
||||
databases.createDocuments(
|
||||
"<DATABASE_ID>", // databaseId
|
||||
"<COLLECTION_ID>", // collectionId
|
||||
listOf(), // documents
|
||||
new CoroutineCallback<>((result, error) -> {
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d("Appwrite", result.toString());
|
||||
})
|
||||
);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import io.appwrite.Client
|
||||
import io.appwrite.coroutines.CoroutineCallback
|
||||
import io.appwrite.services.Databases
|
||||
|
||||
val client = Client(context)
|
||||
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
|
||||
.setKey("") //
|
||||
|
||||
val databases = Databases(client)
|
||||
|
||||
val result = databases.createDocuments(
|
||||
databaseId = "<DATABASE_ID>",
|
||||
collectionId = "<COLLECTION_ID>",
|
||||
documents = listOf(),
|
||||
)
|
||||
@@ -87,7 +87,7 @@ class Client @JvmOverloads constructor(
|
||||
"x-sdk-name" to "Android",
|
||||
"x-sdk-platform" to "client",
|
||||
"x-sdk-language" to "android",
|
||||
"x-sdk-version" to "8.0.0",
|
||||
"x-sdk-version" to "8.0.1",
|
||||
"x-appwrite-response-format" to "1.7.0"
|
||||
)
|
||||
config = mutableMapOf()
|
||||
|
||||
@@ -146,6 +146,64 @@ class Databases(client: Client) : Service(client) {
|
||||
nestedType = classOf(),
|
||||
)
|
||||
|
||||
/**
|
||||
* Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
|
||||
*
|
||||
* @param databaseId Database ID.
|
||||
* @param collectionId 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.
|
||||
* @param documents Array of documents data as JSON objects.
|
||||
* @return [io.appwrite.models.DocumentList<T>]
|
||||
*/
|
||||
suspend fun <T> createDocuments(
|
||||
databaseId: String,
|
||||
collectionId: String,
|
||||
documents: List<Any>,
|
||||
nestedType: Class<T>,
|
||||
): io.appwrite.models.DocumentList<T> {
|
||||
val apiPath = "/databases/{databaseId}/collections/{collectionId}/documents"
|
||||
.replace("{databaseId}", databaseId)
|
||||
.replace("{collectionId}", collectionId)
|
||||
|
||||
val apiParams = mutableMapOf<String, Any?>(
|
||||
"documents" to documents,
|
||||
)
|
||||
val apiHeaders = mutableMapOf<String, String>(
|
||||
"content-type" to "application/json",
|
||||
)
|
||||
val converter: (Any) -> io.appwrite.models.DocumentList<T> = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
io.appwrite.models.DocumentList.from(map = it as Map<String, Any>, nestedType)
|
||||
}
|
||||
return client.call(
|
||||
"POST",
|
||||
apiPath,
|
||||
apiHeaders,
|
||||
apiParams,
|
||||
responseType = classOf(),
|
||||
converter,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
|
||||
*
|
||||
* @param databaseId Database ID.
|
||||
* @param collectionId 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.
|
||||
* @param documents Array of documents data as JSON objects.
|
||||
* @return [io.appwrite.models.DocumentList<T>]
|
||||
*/
|
||||
@Throws(AppwriteException::class)
|
||||
suspend fun createDocuments(
|
||||
databaseId: String,
|
||||
collectionId: String,
|
||||
documents: List<Any>,
|
||||
): io.appwrite.models.DocumentList<Map<String, Any>> = createDocuments(
|
||||
databaseId,
|
||||
collectionId,
|
||||
documents,
|
||||
nestedType = classOf(),
|
||||
)
|
||||
|
||||
/**
|
||||
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user