Instance Method
withSession(_:)
Requests the provided closure be called with a database which is guaranteed to represent a single “session”, suitable for e.g. executing a series of queries representing a transaction.
func withSession<R>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R
Parameters
closureA closure to invoke. The single parameter shall be an implementation of
SQLDatabasewhich represents a single “session”. Implementations may pass the same database on which this method was originally invoked.
Discussion
This method is provided for the benefit of SQLKit drivers which vend concrete database objects which may not necessarily always execute consecutive queries in the same remote context, such as in the case of connection pooling or multiplexing. The default implementation simply passes self to the closure; it is the responsibility of individual drivers to do otherwise as needed.
Default Implementations
SQLDatabase Implementations
withSession(_:)The default implementation forwithSession(_:).
See Also
Query interface
execute(sql:_:)Requests that the given generic SQL query be serialized and executed on the database, and that theonRowclosure be invoked once for each result row the query returns (if any).