TableRequest

public protocol TableRequest

The protocol for all requests that feed from a database table

  • The name of the database table

    Declaration

    Swift

    var databaseTableName: String { get }
  • Creates a request that allows you to define expressions that target a specific database table.

    In the example below, the “team.avgScore < player.score” condition in the ON clause could be not achieved without table aliases.

    struct Player: TableRecord {
        static let team = belongsTo(Team.self)
    }
    
    // SELECT player.*, team.*
    // JOIN team ON ... AND team.avgScore < player.score
    let playerAlias = TableAlias()
    let request = Player
        .all()
        .aliased(playerAlias)
        .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
    

    Declaration

    Swift

    func aliased(_ alias: TableAlias) -> Self

Full Text Search

  • matching(_:) Extension method

    Creates a request with a full-text predicate added to the eventual set of already applied predicates.

    // SELECT * FROM book WHERE book MATCH '...'
    var request = Book.all()
    request = request.matching(pattern)
    

    If the search pattern is nil, the request does not match any database row.

    Declaration

    Swift

    public func matching(_ pattern: FTS3Pattern?) -> Self

Available where Self: FilteredRequest, Self: TypedRequest

  • filter(key:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id = 1
    let request = try Player...filter(key: 1)
    

    Declaration

    Swift

    public func filter<PrimaryKeyType>(key: PrimaryKeyType?) -> Self where PrimaryKeyType : DatabaseValueConvertible

    Parameters

    key

    A primary key

  • filter(keys:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id IN (1, 2, 3)
    let request = try Player...filter(keys: [1, 2, 3])
    

    Declaration

    Swift

    public func filter<Sequence: Swift.Sequence>(keys: Sequence)
    -> Self
    where Sequence.Element: DatabaseValueConvertible

    Parameters

    keys

    A collection of primary keys

  • filter(key:) Extension method

    Creates a request filtered by unique key.

    // SELECT * FROM player WHERE ... email = 'arthur@example.com'
    let request = try Player...filter(key: ["email": "arthur@example.com"])
    

    When executed, this request raises a fatal error if there is no unique index on the key columns.

    Declaration

    Swift

    public func filter(key: [String : DatabaseValueConvertible?]?) -> Self

    Parameters

    key

    A unique key

  • filter(keys:) Extension method

    Creates a request filtered by unique key.

    // SELECT * FROM player WHERE ... email = 'arthur@example.com' OR ...
    let request = try Player...filter(keys: [["email": "arthur@example.com"], ...])
    

    When executed, this request raises a fatal error if there is no unique index on the key columns.

    Declaration

    Swift

    public func filter(keys: [[String : DatabaseValueConvertible?]]) -> Self

    Parameters

    keys

    A collection of unique keys

Available where Self: FilteredRequest, Self: TypedRequest, RowDecoder: Identifiable, RowDecoder.ID: DatabaseValueConvertible

  • filter(id:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id = 1
    let request = try Player...filter(id: 1)
    

    Declaration

    Swift

    public func filter(id: RowDecoder.ID) -> Self

    Parameters

    id

    A primary key

  • filter(ids:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id IN (1, 2, 3)
    let request = try Player...filter(ids: [1, 2, 3])
    

    Declaration

    Swift

    public func filter<Collection: Swift.Collection>(ids: Collection)
    -> Self
    where Collection.Element == RowDecoder.ID

    Parameters

    ids

    A collection of primary keys

Available where Self: FilteredRequest, Self: TypedRequest, RowDecoder: Identifiable, RowDecoder.ID: _OptionalProtocol, RowDecoder.ID.Wrapped: DatabaseValueConvertible

  • filter(id:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id = 1
    let request = try Player...filter(id: 1)
    

    Declaration

    Swift

    public func filter(id: RowDecoder.ID.Wrapped) -> Self

    Parameters

    id

    A primary key

  • filter(ids:) Extension method

    Creates a request filtered by primary key.

    // SELECT * FROM player WHERE ... id IN (1, 2, 3)
    let request = try Player...filter(ids: [1, 2, 3])
    

    Declaration

    Swift

    public func filter<Collection: Swift.Collection>(ids: Collection)
    -> Self
    where Collection.Element == RowDecoder.ID.Wrapped

    Parameters

    ids

    A collection of primary keys

Available where Self: OrderedRequest

Available where Self: AggregatingRequest