ColumnExpression

public protocol ColumnExpression : SQLExpression

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

  • name Default implementation

    The unqualified name of a database column.

    score is a valid unqualified name. player.score is not.

    Default Implementation

    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