Skip to content

Commit c843352

Browse files
committed
wip
1 parent 48f5817 commit c843352

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

Sources/StructuredQueriesCore/Operators.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -730,20 +730,6 @@ extension QueryExpression where QueryValue == String {
730730
LikeOperator(string: self, pattern: pattern, escape: escape)
731731
}
732732

733-
/// A predicate expression from this string expression matched against another _via_ the `MATCH`
734-
/// operator.
735-
///
736-
/// ```swift
737-
/// Reminder.where { $0.title.match("get") }
738-
/// // SELECT … FROM "reminders" WHERE ("reminders"."title" MATCH 'get')
739-
/// ```
740-
///
741-
/// - Parameter pattern: A string expression describing the `MATCH` pattern.
742-
/// - Returns: A predicate expression.
743-
public func match(_ pattern: QueryValue) -> some QueryExpression<Bool> {
744-
BinaryOperator(lhs: self, operator: "MATCH", rhs: pattern)
745-
}
746-
747733
/// A predicate expression from this string expression matched against another _via_ the `LIKE`
748734
/// operator given a prefix.
749735
///

Sources/StructuredQueriesCore/SQLite/FTS5.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
/// A virtual table using the FTS5 extension.
2+
///
3+
/// Apply this protocol to a `@Table` declaration to introduce FTS5 helpers.
14
public protocol FTS5: Table {}
2-
35
extension 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

2142
extension 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

Comments
 (0)