Instance Method
delete(fromDb:uri:rev:eventLoopGroup:)
Deletes a document from a specified database on the CouchDB server.
func delete(fromDb dbName: String, uri: String, rev: String, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> CouchUpdateResponse
Parameters
- dbName
The name of the database from which the document will be deleted.
- uri
The URI path of the specific document within the database.
- rev
The revision number of the document to be deleted.
- eventLoopGroup
An optional EventLoopGroup for executing network requests. If not provided, the function uses a shared instance of HTTPClient.
Return Value
A CouchUpdateResponse object containing the result of the delete operation.
Discussion
This asynchronous function sends a DELETE request to the CouchDB server to remove a document identified by its URI and revision number. It supports using a custom EventLoopGroup for managing network operations.
Throws
A CouchDBClientError if the operation fails, including: .unauthorized if authentication fails, .deleteError(error:) when CouchDB reports the document as missing, or .unknownResponse when CouchDB returns an unexpected error payload.
Function Workflow:
Constructs a DELETE request using the database name, document URI, and revision query parameter.
Executes the request using an authenticated client and buffers the response body.
Throws .deleteError(error:) when CouchDB responds with 404 Not Found.
Decodes and returns CouchUpdateResponse for successful responses.
Returns CouchUpdateResponse(ok: false, id: "", rev: "") when the response body is empty.
Example Usage:
let response = try await couchDBClient.delete(
fromDb: "myDatabase",
uri: "documentID",
rev: "documentRevision"
)
print(response) // Response includes operation status and revision token
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle thrown errors appropriately, especially for authentication issues or unexpected server responses.