Skip to content

Instance Method

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

iOS 16.0+ iPadOS 16.0+ Mac Catalyst 16.0+ macOS 13.0+ tvOS 16.0+ watchOS 9.0+
Run a query on the Postgres server the client is connected to.
func query<Result>(_ query: PostgresQuery, logger: Logger? = nil, summary: String? = nil, file: String = #fileID, line: Int = #line, _ body: (PostgresRowSequence) async throws -> Result) async throws -> (result: Result, metadata: PostgresQueryMetadata)

Parameters

query

The PostgresQuery to run

logger

The Logger to log into for the query

summary

A low-cardinality summary of the query (e.g. SELECT users), used as the span’s name and recorded as db.query.summary. Must not contain values, such as an id.

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 and the query metadata.

Discussion

The result of the query can only be consumed inside of the body closure. Attempting to consume the stream outside of the closure is a programmer error, and will trigger a precondition failure.