Skip to content

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

closure

A closure to invoke. The single parameter shall be an implementation of SQLDatabase which 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

See Also

Query interface

  • execute(sql:_:)
    Requests that the given generic SQL query be serialized and executed on the database, and that the onRow closure be invoked once for each result row the query returns (if any).