OrderedRequest
public protocol OrderedRequest
The protocol for all requests that can be ordered.
-
order(_:
Default implementation) Creates a request with the provided orderings promise.
// SELECT * FROM player ORDER BY name var request = Player.all() request = request.order { _ in [Column("name")] }
Any previous ordering is replaced:
// SELECT * FROM player ORDER BY name request .order{ _ in [Column("email")] } .reversed() .order{ _ in [Column("name")] }
Default Implementation
Creates a request with the provided orderings.
// SELECT * FROM player ORDER BY name var request = Player.all() request = request.order(Column("name"))
Any previous ordering is replaced:
// SELECT * FROM player ORDER BY name request .order(Column("email")) .reversed() .order(Column("name"))
Declaration
Swift
func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> Self
-
Creates a request that reverses applied orderings.
// SELECT * FROM player ORDER BY name DESC var request = Player.all().order(Column("name")) request = request.reversed()
If no ordering was applied, the returned request is identical.
// SELECT * FROM player var request = Player.all() request = request.reversed()
Declaration
Swift
func reversed() -> Self
-
Creates a request without any ordering.
// SELECT * FROM player var request = Player.all().order(Column("name")) request = request.unordered()
Declaration
Swift
func unordered() -> Self
-
order(sql:
Extension methodarguments: ) Creates a request sorted according to sql.
// SELECT * FROM player ORDER BY name var request = Player.all() request = request.order(sql: "name")
Any previous ordering is replaced:
// SELECT * FROM player ORDER BY name request .order(sql: "email") .order(sql: "name")
Declaration
Swift
public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self
-
order(literal:
Extension method) Creates a request sorted according to an SQL literal.
// SELECT * FROM player ORDER BY name var request = Player.all() request = request.order(literal: "name")
Any previous ordering is replaced:
// SELECT * FROM player ORDER BY name request .order(literal: "email") .order(literal: "name")
Declaration
Swift
public func order(literal sqlLiteral: SQL) -> Self