Skip to content

Commit 3616df2

Browse files
authored
Improve FTS docs (#140)
Add an important note and clean up other docs.
1 parent b5b5a9e commit 3616df2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Sources/StructuredQueriesCore/SQLite/FTS5.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import IssueReporting
22

33
/// A virtual table using the FTS5 extension.
44
///
5-
/// Apply this protocol to a `@Table` declaration to introduce FTS5 helpers.
5+
/// Apply this protocol to a `@Table` declaration to introduce [FTS5] helpers.
6+
///
7+
/// [FTS5]: https://www.sqlite.org/fts5.html
68
public protocol FTS5: Table {}
79

810
extension TableDefinition where QueryValue: FTS5 {
@@ -13,6 +15,16 @@ extension TableDefinition where QueryValue: FTS5 {
1315
/// // SELECT … FROM "reminderTexts" WHERE ("reminderTexts" MATCH 'get')
1416
/// ```
1517
///
18+
/// > Important: Avoid passing a string entered by the user directly to this operator. FTS5
19+
/// > queries have a distinct [syntax] that can specify particular columns and refine a search in
20+
/// > various ways. If FTS5 is given a query with invalid syntax, it can even throw SQL errors at
21+
/// > runtime.
22+
/// >
23+
/// > Instead, consider transforming the user's input into a query by quoting, prefixing, and/or
24+
/// > combining inputs from your UI into a valid query before handing it off to SQLite.
25+
///
26+
/// [syntax]: https://www.sqlite.org/fts5.html#full_text_query_syntax
27+
///
1628
/// - Parameter pattern: A string expression describing the `MATCH` pattern.
1729
/// - Returns: A predicate expression.
1830
public func match(_ pattern: some StringProtocol) -> some QueryExpression<Bool> {
@@ -60,7 +72,7 @@ extension TableColumnExpression where Root: FTS5 {
6072
///
6173
/// ```swift
6274
/// ReminderText.where { $0.title.match("get") }
63-
/// // SELECT … FROM "reminderTexts" WHERE ("reminderTexts"."title" MATCH 'get')
75+
/// // SELECT … FROM "reminderTexts" WHERE ("reminderTexts" MATCH 'title:\"get\"')
6476
/// ```
6577
///
6678
/// - Parameter pattern: A string expression describing the `MATCH` pattern.

0 commit comments

Comments
 (0)