You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: library/src/main/java/io/appwrite/services/Databases.kt
+49-35Lines changed: 49 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -147,35 +147,38 @@ class Databases(client: Client) : Service(client) {
147
147
)
148
148
149
149
/**
150
-
* 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.
150
+
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
151
151
*
152
152
* @param databaseId Database ID.
153
-
* @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.
154
-
* @param documents Array of documents data as JSON objects.
155
-
* @return [io.appwrite.models.DocumentList<T>]
153
+
* @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
154
+
* @param documentId Document ID.
155
+
* @param queries 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.
156
+
* @return [io.appwrite.models.Document<T>]
156
157
*/
157
-
suspendfun <T> createDocuments(
158
+
@JvmOverloads
159
+
suspendfun <T> getDocument(
158
160
databaseId:String,
159
161
collectionId:String,
160
-
documents:List<Any>,
162
+
documentId:String,
163
+
queries:List<String>? = null,
161
164
nestedType:Class<T>,
162
-
): io.appwrite.models.DocumentList<T> {
163
-
val apiPath ="/databases/{databaseId}/collections/{collectionId}/documents"
165
+
): io.appwrite.models.Document<T> {
166
+
val apiPath ="/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
164
167
.replace("{databaseId}", databaseId)
165
168
.replace("{collectionId}", collectionId)
169
+
.replace("{documentId}", documentId)
166
170
167
171
val apiParams = mutableMapOf<String, Any?>(
168
-
"documents" to documents,
172
+
"queries" to queries,
169
173
)
170
174
val apiHeaders = mutableMapOf<String, String>(
171
-
"content-type" to "application/json",
172
175
)
173
-
val converter: (Any) -> io.appwrite.models.DocumentList<T> = {
176
+
val converter: (Any) -> io.appwrite.models.Document<T> = {
174
177
@Suppress("UNCHECKED_CAST")
175
-
io.appwrite.models.DocumentList.from(map = it asMap<String, Any>, nestedType)
178
+
io.appwrite.models.Document.from(map = it asMap<String, Any>, nestedType)
176
179
}
177
180
return client.call(
178
-
"POST",
181
+
"GET",
179
182
apiPath,
180
183
apiHeaders,
181
184
apiParams,
@@ -185,40 +188,46 @@ class Databases(client: Client) : Service(client) {
185
188
}
186
189
187
190
/**
188
-
* 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.
191
+
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
189
192
*
190
193
* @param databaseId Database ID.
191
-
* @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.
192
-
* @param documents Array of documents data as JSON objects.
193
-
* @return [io.appwrite.models.DocumentList<T>]
194
+
* @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
195
+
* @param documentId Document ID.
196
+
* @param queries 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.
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
215
+
* Create or update a Document. 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.
209
216
*
210
217
* @param databaseId Database ID.
211
-
* @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
218
+
* @param collectionId Collection ID.
212
219
* @param documentId Document ID.
213
-
* @param queries 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.
220
+
* @param data Document data as JSON object. Include all required attributes of the document to be created or updated.
221
+
* @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).
214
222
* @return [io.appwrite.models.Document<T>]
215
223
*/
216
224
@JvmOverloads
217
-
suspendfun <T> getDocument(
225
+
suspendfun <T> upsertDocument(
218
226
databaseId:String,
219
227
collectionId:String,
220
228
documentId:String,
221
-
queries:List<String>? = null,
229
+
data:Any,
230
+
permissions:List<String>? = null,
222
231
nestedType:Class<T>,
223
232
): io.appwrite.models.Document<T> {
224
233
val apiPath ="/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
@@ -227,16 +236,18 @@ class Databases(client: Client) : Service(client) {
227
236
.replace("{documentId}", documentId)
228
237
229
238
val apiParams = mutableMapOf<String, Any?>(
230
-
"queries" to queries,
239
+
"data" to data,
240
+
"permissions" to permissions,
231
241
)
232
242
val apiHeaders = mutableMapOf<String, String>(
243
+
"content-type" to "application/json",
233
244
)
234
245
val converter: (Any) -> io.appwrite.models.Document<T> = {
235
246
@Suppress("UNCHECKED_CAST")
236
247
io.appwrite.models.Document.from(map = it asMap<String, Any>, nestedType)
237
248
}
238
249
return client.call(
239
-
"GET",
250
+
"PUT",
240
251
apiPath,
241
252
apiHeaders,
242
253
apiParams,
@@ -246,26 +257,29 @@ class Databases(client: Client) : Service(client) {
246
257
}
247
258
248
259
/**
249
-
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
260
+
* Create or update a Document. 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.
250
261
*
251
262
* @param databaseId Database ID.
252
-
* @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
263
+
* @param collectionId Collection ID.
253
264
* @param documentId Document ID.
254
-
* @param queries 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.
265
+
* @param data Document data as JSON object. Include all required attributes of the document to be created or updated.
266
+
* @param permissions An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).
0 commit comments