SQLSpecificExpressible
public protocol SQLSpecificExpressible : SQLExpressible, SQLOrderingTerm, SQLSelectable
SQLSpecificExpressible
is a protocol for all database-specific types that
can be turned into an SQL expression. Types whose existence is not purely
dedicated to the database should adopt the SQLExpressible
protocol instead.
For example, Column
is a type that only exists to help you build requests,
and it adopts SQLSpecificExpressible
.
On the other side, Int
adopts SQLExpressible
.
-
sqlSelection
Extension methodDeclaration
Swift
public var sqlSelection: SQLSelection { get }
-
sqlOrdering
Extension methodDeclaration
Swift
public var sqlOrdering: SQLOrdering { get }
-
asc
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
Declaration
Swift
public var asc: SQLOrdering { get }
-
desc
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
Declaration
Swift
public var desc: SQLOrdering { get }
-
ascNullsLast
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
-
descNullsFirst
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
-
ascNullsLast
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
Declaration
Swift
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *) public var ascNullsLast: SQLOrdering { get }
-
descNullsFirst
Extension methodReturns a value that can be used as an argument to QueryInterfaceRequest.order()
See https://github.com/groue/GRDB.swift/#the-query-interface
Declaration
Swift
@available(macOS 11.0, iOS 14, tvOS 14, watchOS 7, *) public var descNullsFirst: SQLOrdering { get }
-
forKey(_:
Extension method) Returns an aliased column.
For example:
// SELECT (width * height) AS area FROM shape let area = (Column("width") * Column("height")).forKey("area") let request = Shape.select(area) if let row = try Row.fetchOne(db, request) { let area: Int = row["area"] }
If you need to refer to the aliased column in another part of a request, use
Column(...).detached
. For example:// SELECT (width * height) AS area FROM shape ORDER BY area let area = (Column("width") * Column("height")).forKey("area") let request = Shape .select(area) .order(Column("area").detached) let rows = try Row.fetchCursor(db, request) while let row = try rows.next() { let area: Int = row["area"] }
Declaration
Swift
public func forKey(_ key: String) -> SQLSelection
-
forKey(_:
Extension method) Returns an aliased column with the same name as the coding key.
For example:
struct Shape: Decodable, FetchableRecord, TableRecord { let width: Int let height: Int let area: Int static let databaseSelection: [SQLSelectable] = [ Column(CodingKeys.width), Column(CodingKeys.height), (Column(CodingKeys.width) * Column(CodingKeys.height)).forKey(CodingKeys.area), ] } // SELECT width, height, (width * height) AS area FROM shape let shapes: [Shape] = try Shape.fetchAll(db)
See
forKey(_ key: String)
for more information.Declaration
Swift
public func forKey(_ key: CodingKey) -> SQLSelection
-
collating(_:
Extension method) Returns a collated expression.
For example:
Player.filter(Column("email").collating(.nocase) == "contact@example.com")
Declaration
Swift
public func collating(_ collation: Database.CollationName) -> SQLExpression
-
collating(_:
Extension method) Returns a collated expression.
For example:
Player.filter(Column("name").collating(.localizedStandardCompare) == "Hervé")
Declaration
Swift
public func collating(_ collation: DatabaseCollation) -> SQLExpression
-
like(_:
Extension methodescape: ) An SQL expression with the
LIKE
SQL operator.// email LIKE '%@example.com" Column("email").like("%@example.com") // title LIKE '%10\%%' ESCAPE '\' Column("title").like("%10\\%%", escape: "\\")
Declaration
Swift
public func like(_ pattern: SQLExpressible, escape: SQLExpressible? = nil) -> SQLExpression