Skip to content

Instance Method

query(_:logger:file:line:_:)

Run a query on the Postgres server the connection is connected to.
func query<Result>(_ query: PostgresQuery, logger: Logger, file: String = #fileID, line: Int = #line, _ body: (PostgresRowSequence) async throws -> Result) async throws -> Result

Parameters

query

The PostgresQuery to run

logger

The Logger to log into for the query

file

The file the query was started in. Used for better error reporting.

line

The line the query was started in. Used for better error reporting.

body

The closure that’s used to consume the query result.

Return Value

The result of the body closure.

Discussion

The result of the query can only be consumed inside of the body closure and attempting to consume the stream outside of the closure will throw PSQLError.rowSequenceUsedOutsideScope. Rows that were already buffered when body returned are still delivered before the error is thrown.