ColumnExpression
public protocol ColumnExpression : SQLSpecificExpressible
Adopt the ColumnExpression protocol when you define a column type.
You can, for example, define a String-based column enum:
enum Columns: String, ColumnExpression {
case id, name, score
}
let arthur = try Player.filter(Columns.name == "Arthur").fetchOne(db)
You can also define a genuine column type:
struct MyColumn: ColumnExpression {
var name: String
var sqlType: String
}
let nameColumn = MyColumn(name: "name", sqlType: "VARCHAR")
let arthur = try Player.filter(nameColumn == "Arthur").fetchOne(db)
-
The unqualified name of a database column.
“score” is a valid unqualified name. “player.score” is not.
Declaration
Swift
var name: String { get }
-
match(_:
Extension method) A matching SQL expression with the
MATCH
SQL operator.// content MATCH '...' Column("content").match(pattern)
If the search pattern is nil, SQLite will evaluate the expression to false.
Declaration
Swift
public func match(_ pattern: FTS3Pattern?) -> SQLExpression
-
set(to:
Extension method) Creates an assignment to a value.
Column("valid").set(to: true) Column("score").set(to: 0) Column("score").set(to: nil) Column("score").set(to: Column("score") + Column("bonus")) try dbQueue.write { db in // UPDATE player SET score = 0 try Player.updateAll(db, Column("score").set(to: 0)) }
Declaration
Swift
public func set(to value: SQLExpressible?) -> ColumnAssignment
-
sqlExpression
Extension methodDeclaration
Swift
public var sqlExpression: SQLExpression { get }
-
rowID
Extension methodThe hidden rowID column
Declaration
Swift
public static var rowID: Self { get }