Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Sources/StructuredQueriesCore/SQLite/FTS5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import IssueReporting

/// A virtual table using the FTS5 extension.
///
/// Apply this protocol to a `@Table` declaration to introduce FTS5 helpers.
/// Apply this protocol to a `@Table` declaration to introduce [FTS5] helpers.
///
/// [FTS5]: https://www.sqlite.org/fts5.html
public protocol FTS5: Table {}

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