Instance Method
execute(_:logger:file:line:_:)
body closure’s result.func execute<Statement, Row, Result>(_ preparedStatement: Statement, logger: Logger, file: String = #fileID, line: Int = #line, _ body: (AsyncThrowingMapSequence<PostgresRowSequence, Row>) async throws -> Result) async throws -> (result: Result, metadata: PostgresQueryMetadata) where Statement : PostgresPreparedStatement, Row == Statement.Row
Parameters
preparedStatementThe
PostgresPreparedStatementto executeloggerThe
Loggerto log into for the statementfileThe file the statement was executed in. Used for better error reporting.
lineThe line the statement was executed in. Used for better error reporting.
bodyThe closure that’s used to consume the decoded rows. Must consume the sequence to its end.
Return Value
The result of the body closure and the statement metadata.
Discussion
The result of the statement 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.
The metadata is derived from the command tag the server sends after the last row, so body must iterate the sequence to its end. If it returns early the statement is cancelled and the method throws PSQLError.rowSequenceNotFullyConsumed.