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)

See https://github.com/groue/GRDB.swift#the-query-interface

  • 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

ColumnAssignment

  • 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 method

    Declaration

    Swift

    public var sqlExpression: SQLExpression { get }

Available where Self == Column

  • rowID Extension method

    The hidden rowID column

    Declaration

    Swift

    public static var rowID: Self { get }