TableRequest
The protocol for all requests that feed from a database table
-
The name of the database table
-
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")])
-
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.
-
filter(key:
Extension method) Creates a request filtered by primary key.
// SELECT * FROM player WHERE ... id = 1 let request = try Player...filter(key: 1)
-
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])
-
orderByPrimaryKey()
Extension methodCreates a request ordered by primary key.
-
groupByPrimaryKey()
Extension methodCreates a request grouped by primary key.