Skip to content

Class

SQLReturningResultBuilder

A builder returned from the methods of SQLReturningBuilder; this builder wraps the original builder with one which provides SQLQueryFetcher conformance. As such, the returning(_:) methods must always be the last ones in any call chain.
final class SQLReturningResultBuilder<QueryBuilder> where QueryBuilder : SQLReturningBuilder

Overview

Example:

// Correct:
db.insert(into: "foo").model(foo).returning("id").first() // Returns a row containing an "id" column

// Incorrect:
db.insert(into: "foo").returning("id").model(foo).first() // Syntax error

Note

The only reason we can’t make SQLReturningResultBuilder conditionally conform to the other builder protocols and thus remove the “last-in-chain” restriction is that it has historically exposed its query and database properties as both mutable and public, whereas they are get-only in the SQLQueryBuilder protocol - a classic example of Hyrum’s Law and its consequences. Conforming SQLReturningBuilder directly to SQLQueryFetcher would have been a simpler approach, but then the availability of the fetching methods would not have been contingent upon the presence of a returning clause.

Topics

Instance Properties

  • database
    Connection to execute query on.
  • query
    Query being built.

Relationships

Conforms To

See Also

Query Builders