Instance Method
dbExists(_:eventLoopGroup:)
Checks if a database exists on the CouchDB server.
func dbExists(_ dbName: String, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> Bool
Parameters
- dbName
The name of the database to check for existence.
- eventLoopGroup
An optional EventLoopGroup used for executing network requests. If not provided, the function defaults to using a shared instance of HTTPClient.
Return Value
A Bool indicating whether the database exists (true) or not (false).
Discussion
This asynchronous function sends a HEAD request to the CouchDB server to verify the existence of a specified database. It supports using a custom NIO’s EventLoopGroup for managing network operations.
Throws
A CouchDBClientError if authentication fails, plus any underlying request execution error.
Function Workflow:
Constructs a HEAD request for the provided database name.
Executes the request using an authenticated client, optionally scoped to the provided EventLoopGroup.
Returns true when the response status is .ok, and false otherwise.
Example Usage:
let doesExist = try await couchDBClient.dbExists("myDatabase")
print("Database exists: \(doesExist)")
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle thrown errors appropriately, especially authentication-related issues.