@@ -218,6 +218,86 @@ open class Databases: Service {
218218 )
219219 }
220220
221+ ///
222+ /// Create or update a Document. Before using this route, you should create a
223+ /// new collection resource using either a [server
224+ /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
225+ /// API or directly from your database console.
226+ ///
227+ /// @param String databaseId
228+ /// @param String collectionId
229+ /// @param String documentId
230+ /// @param Any data
231+ /// @param [String] permissions
232+ /// @throws Exception
233+ /// @return array
234+ ///
235+ open func upsertDocument< T> (
236+ databaseId: String ,
237+ collectionId: String ,
238+ documentId: String ,
239+ data: Any ,
240+ permissions: [ String ] ? = nil ,
241+ nestedType: T . Type
242+ ) async throws -> AppwriteModels . Document < T > {
243+ let apiPath : String = " /databases/{databaseId}/collections/{collectionId}/documents/{documentId} "
244+ . replacingOccurrences ( of: " {databaseId} " , with: databaseId)
245+ . replacingOccurrences ( of: " {collectionId} " , with: collectionId)
246+ . replacingOccurrences ( of: " {documentId} " , with: documentId)
247+
248+ let apiParams : [ String : Any ? ] = [
249+ " data " : data,
250+ " permissions " : permissions
251+ ]
252+
253+ let apiHeaders : [ String : String ] = [
254+ " content-type " : " application/json "
255+ ]
256+
257+ let converter : ( Any ) -> AppwriteModels . Document < T > = { response in
258+ return AppwriteModels . Document. from ( map: response as! [ String : Any ] )
259+ }
260+
261+ return try await client. call (
262+ method: " PUT " ,
263+ path: apiPath,
264+ headers: apiHeaders,
265+ params: apiParams,
266+ converter: converter
267+ )
268+ }
269+
270+ ///
271+ /// Create or update a Document. Before using this route, you should create a
272+ /// new collection resource using either a [server
273+ /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
274+ /// API or directly from your database console.
275+ ///
276+ /// @param String databaseId
277+ /// @param String collectionId
278+ /// @param String documentId
279+ /// @param Any data
280+ /// @param [String] permissions
281+ /// @throws Exception
282+ /// @return array
283+ ///
284+ open func upsertDocument(
285+ databaseId: String ,
286+ collectionId: String ,
287+ documentId: String ,
288+ data: Any ,
289+ permissions: [ String ] ? = nil
290+ ) async throws -> AppwriteModels . Document < [ String : AnyCodable ] > {
291+ return try await upsertDocument (
292+ databaseId: databaseId,
293+ collectionId: collectionId,
294+ documentId: documentId,
295+ data: data,
296+ permissions: permissions,
297+ nestedType: [ String : AnyCodable ] . self
298+ )
299+ }
300+
221301 ///
222302 /// Update a document by its unique ID. Using the patch method you can pass
223303 /// only specific fields that will get updated.
0 commit comments