Skip to content

Instance Method

withConnection(_:)

Call the provided closure with a concrete SQLiteConnection instance, concurrency version.
func withConnection<T>(_ closure: @escaping @Sendable (SQLiteConnection) async throws -> T) async throws -> T

Parameters

closure

The closure to invoke. Unless the closure changes the connection’s state itself or the connection is closed by SQLite due to error, it is guaranteed to remain valid until the future returned by the closure is completed or failed.

Return Value

A future signaling completion of the closure and containing the closure’s result, if any.

Discussion

This method is required to provide a connection object which executes all queries directed to it in the same “session” (e.g. always on the same connection, such as without rotating through a pool). A default implementation is provided for protocol implementors who predate the existence of this requirement.

Default Implementations

SQLiteDatabase Implementations