Instance Method
delete(fromDb:doc:eventLoopGroup:)
Deletes a document conforming to CouchDBRepresentable from a specified database on the CouchDB server.
func delete(fromDb dbName: String, doc: any CouchDBRepresentable, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> CouchUpdateResponse
Parameters
- dbName
The name of the database from which the document will be deleted.
- doc
The document of type CouchDBRepresentable to be deleted.
- eventLoopGroup
An optional EventLoopGroup for executing network requests. If not provided, a shared instance of HTTPClient is used.
Return Value
A CouchUpdateResponse object containing the result of the delete operation.
Discussion
This asynchronous function removes a document from the specified database. The document must conform to the CouchDBRepresentable protocol, which includes the _id and _rev properties required for the deletion process. It supports using a custom EventLoopGroup for network operations.
Throws
A CouchDBClientError if the operation fails, including: .revMissing if the document’s _rev property is missing.
Function Workflow:
Validates the presence of the document’s _rev property.
Delegates to delete(fromDb:uri:rev:eventLoopGroup:) using the document’s _id and _rev.
Example Usage:
let deleteResult = try await couchDBClient.delete(
fromDb: "myDatabase",
doc: myDocument
)
print(deleteResult) // Response includes operation status and revision token
Note
Ensure that the CouchDB server is operational and accessible before using this function. Handle thrown errors appropriately, especially for missing document properties or unexpected server responses.