SelectionRequest

public protocol SelectionRequest

The protocol for all requests that can refine their selection.

  • select(_:) Default implementation

    Creates a request which selects selection promise.

    // SELECT id, email FROM player
    var request = Player.all()
    request = request.select { db in [Column("id"), Column("email") })
    

    Any previous selection is replaced:

    // SELECT email FROM player
    request
        .select { db in [Column("id")] }
        .select { db in [Column("email")] }
    

    Default Implementation

    Creates a request which selects selection.

    // SELECT id, email FROM player
    var request = Player.all()
    request = request.select(Column("id"), Column("email"))
    

    Any previous selection is replaced:

    // SELECT email FROM player
    request
        .select(Column("id"))
        .select(Column("email"))
    

    Declaration

    Swift

    func select(_ selection: @escaping (Database) throws -> [SQLSelectable]) -> Self
  • annotated(with:) Default implementation

    Creates a request which appends selection promise.

    // SELECT id, email, name FROM player
    var request = Player.all()
    request = request
        .select([Column("id"), Column("email")])
        .annotated(with: { db in [Column("name")] })
    

    Default Implementation

    Creates a request which appends selection.

    // SELECT id, email, name FROM player
    var request = Player.all()
    request = request
        .select([Column("id"), Column("email")])
        .annotated(with: Column("name"))
    

    Declaration

    Swift

    func annotated(with selection: @escaping (Database) throws -> [SQLSelectable]) -> Self

SelectionRequest

  • select(sql:arguments:) Extension method

    Creates a request which selects sql.

    // SELECT id, email FROM player
    var request = Player.all()
    request = request.select(sql: "id, email")
    

    Any previous selection is replaced:

    // SELECT email FROM player
    request
        .select(sql: "id")
        .select(sql: "email")
    

    Declaration

    Swift

    public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self
  • select(literal:) Extension method

    Creates a request which selects an SQL literal.

    Literals allow you to safely embed raw values in your SQL, without any risk of syntax errors or SQL injection:

    // SELECT id, email, score + 1000 FROM player
    let bonus = 1000
    var request = Player.all()
    request = request.select(literal: """
        id, email, score + \(bonus)
        """)
    

    Any previous selection is replaced:

    // SELECT email FROM player
    request
        .select(...)
        .select(literal: "email")
    

    Declaration

    Swift

    public func select(literal sqlLiteral: SQL) -> Self