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
+72Lines changed: 72 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,78 @@ class Databases(client: Client) : Service(client) {
211
211
nestedType = classOf(),
212
212
)
213
213
214
+
/**
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.
216
+
*
217
+
* @param databaseId Database ID.
218
+
* @param collectionId Collection ID.
219
+
* @param documentId Document ID.
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).
222
+
* @return [io.appwrite.models.Document<T>]
223
+
*/
224
+
@JvmOverloads
225
+
suspendfun <T> upsertDocument(
226
+
databaseId:String,
227
+
collectionId:String,
228
+
documentId:String,
229
+
data:Any,
230
+
permissions:List<String>? = null,
231
+
nestedType:Class<T>,
232
+
): io.appwrite.models.Document<T> {
233
+
val apiPath ="/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
234
+
.replace("{databaseId}", databaseId)
235
+
.replace("{collectionId}", collectionId)
236
+
.replace("{documentId}", documentId)
237
+
238
+
val apiParams = mutableMapOf<String, Any?>(
239
+
"data" to data,
240
+
"permissions" to permissions,
241
+
)
242
+
val apiHeaders = mutableMapOf<String, String>(
243
+
"content-type" to "application/json",
244
+
)
245
+
val converter: (Any) -> io.appwrite.models.Document<T> = {
246
+
@Suppress("UNCHECKED_CAST")
247
+
io.appwrite.models.Document.from(map = it asMap<String, Any>, nestedType)
248
+
}
249
+
return client.call(
250
+
"PUT",
251
+
apiPath,
252
+
apiHeaders,
253
+
apiParams,
254
+
responseType = classOf(),
255
+
converter,
256
+
)
257
+
}
258
+
259
+
/**
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.
261
+
*
262
+
* @param databaseId Database ID.
263
+
* @param collectionId Collection ID.
264
+
* @param documentId Document ID.
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