Instance Method
find(inDB:body:eventLoopGroup:)
Executes a raw _find request against a specified database.
func find(inDB dbName: String, body: HTTPClientRequest.Body, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> HTTPClientResponse
Parameters
- dbName
The name of the database in which to execute the query.
- body
The HTTPClientRequest.Body containing the encoded query to be sent to the server.
- eventLoopGroup
An optional EventLoopGroup for executing network requests. If not provided, the function uses a shared instance of HTTPClient.
Return Value
An HTTPClientResponse whose body has already been buffered in memory.
Discussion
This method sends a custom request body to CouchDB’s _find endpoint and returns the raw HTTPClientResponse. Before returning, it buffers the response body in memory so callers can decode it manually.
Throws
A CouchDBClientError if the operation fails, including: .unauthorized: If authentication fails.
Example Usage:
Perform a Find Query:
let selector = ["selector": ["name": "Greg"]]
let bodyData = try JSONEncoder().encode(selector)
let findResponse = try await couchDBClient.find(
inDB: "myDatabase",
body: .bytes(ByteBuffer(data: bodyData))
)
print(findResponse.status)
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle thrown errors appropriately, especially authentication-related issues.