1+ /// A virtual table using the FTS5 extension.
2+ ///
3+ /// Apply this protocol to a `@Table` declaration to introduce FTS5 helpers.
14public protocol FTS5 : Table { }
2-
35extension TableDefinition where QueryValue: FTS5 {
6+ @available ( * , deprecated, message: " Virtual tables are not 'rowid' tables " )
7+ public var rowid : some QueryExpression < Int > {
8+ SQLQueryExpression (
9+ """
10+ \( QueryValue . self) . " rowid "
11+ """
12+ )
13+ }
14+
15+ /// An expression representing the search result's rank.
416 public var rank : some QueryExpression < Double ? > {
517 SQLQueryExpression (
618 """
@@ -9,6 +21,15 @@ extension TableDefinition where QueryValue: FTS5 {
921 )
1022 }
1123
24+ /// A predicate expression from this table matched against another _via_ the `MATCH` operator.
25+ ///
26+ /// ```swift
27+ /// ReminderText.where { $0.match("get") }
28+ /// // SELECT … FROM "reminderTexts" WHERE ("reminderTexts" MATCH 'get')
29+ /// ```
30+ ///
31+ /// - Parameter pattern: A string expression describing the `MATCH` pattern.
32+ /// - Returns: A predicate expression.
1233 public func match( _ pattern: some QueryExpression < String > ) -> some QueryExpression < Bool > {
1334 SQLQueryExpression (
1435 """
@@ -19,6 +40,12 @@ extension TableDefinition where QueryValue: FTS5 {
1940}
2041
2142extension TableColumnExpression where Root: FTS5 {
43+ /// A string expression highlighting matches in this column using the given delimiters.
44+ ///
45+ /// - Parameters:
46+ /// - open: An opening delimiter denoting the beginning of a match, _e.g._ `"<b>"`.
47+ /// - close: A closing delimiter denoting the end of a match, _e.g._, `"</b>"`.
48+ /// - Returns: A string expression highlighting matches in this column.
2249 public func highlight(
2350 _ open: String ,
2451 _ close: String
@@ -37,4 +64,17 @@ extension TableColumnExpression where Root: FTS5 {
3764 """
3865 )
3966 }
67+
68+ /// A predicate expression from this column matched against another _via_ the `MATCH` operator.
69+ ///
70+ /// ```swift
71+ /// ReminderText.where { $0.title.match("get") }
72+ /// // SELECT … FROM "reminderTexts" WHERE ("reminderTexts"."title" MATCH 'get')
73+ /// ```
74+ ///
75+ /// - Parameter pattern: A string expression describing the `MATCH` pattern.
76+ /// - Returns: A predicate expression.
77+ public func match( _ pattern: some QueryExpression < String > ) -> some QueryExpression < Bool > {
78+ BinaryOperator ( lhs: self , operator: " MATCH " , rhs: pattern)
79+ }
4080}
0 commit comments