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
-
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 -
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.
The selection defaults to all columns. This default can be changed for all requests by the
TableRecord.databaseSelectionproperty, or for individual requests with theTableRecord.selectmethod.Declaration
Swift
public func matching(_ pattern: FTS5Pattern?) -> Self
-
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 : DatabaseValueConvertibleParameters
keyA 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: DatabaseValueConvertibleParameters
keysA 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?]?) -> SelfParameters
keyA 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?]]) -> SelfParameters
keysA collection of unique keys
Available where Self: FilteredRequest, Self: JoinableRequest, // forRowDecoderRowDecoder: 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) -> SelfParameters
idA 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.IDParameters
idsA collection of primary keys
Available where Self: FilteredRequest, Self: JoinableRequest, // forRowDecoderRowDecoder: 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) -> SelfParameters
idA 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.WrappedParameters
idsA collection of primary keys
-
orderByPrimaryKey()Extension methodCreates a request ordered by primary key.
Declaration
Swift
public func orderByPrimaryKey() -> Self
-
groupByPrimaryKey()Extension methodCreates a request grouped by primary key.
Declaration
Swift
public func groupByPrimaryKey() -> Self
View on GitHub
Install in Dash
TableRequest Protocol Reference