Instance Method
createDB(_:eventLoopGroup:)
Creates a new database on the CouchDB server.
@discardableResult func createDB(_ dbName: String, eventLoopGroup: (any EventLoopGroup)? = nil) async throws -> UpdateDBResponse
Parameters
- dbName
The name of the database to be created.
- eventLoopGroup
An optional EventLoopGroup for executing network requests. If not provided, the function defaults to using a shared instance of HTTPClient.
Return Value
An UpdateDBResponse object that contains the result of the database creation operation.
Discussion
This method sends a PUT request for the specified database name and decodes CouchDB’s update response. It supports using a custom EventLoopGroup for network operations.
Throws
A CouchDBClientError if authentication fails, the response body is missing, or CouchDB returns an error payload that maps to .insertError(error:). Non-CouchDB decoding failures are propagated as the underlying decoding error.
Example Usage:
let creationResult = try await couchDBClient.createDB("newDatabase")
print("Database creation successful: \(creationResult.ok)")
Note
Ensure that the CouchDB server is running and accessible before calling this function. Handle any thrown errors appropriately, including authentication issues and potential conflicts if the database already exists.