Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Full-text search

## Overview

StructuredQueries comes with built-in support for SQLite's FTS5 module.

## Topics

### Virtual tables

- ``FTS5``

### Performing searches

- ``TableDefinition/match(_:)``
- ``TableColumnExpression/match(_:)``

### Ranking searches

- ``TableDefinition/rank``
- ``TableDefinition/bm25(_:)``

### Highlighting results

- ``TableColumnExpression/highlight(_:_:)``
- ``TableColumnExpression/snippet(_:_:_:_:)``
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ Or you can conditionally upsert from given indexed columns using `onConflict:doU
}
}

Upsert clauses have an additional, special ``Updates/excluded`` qualifier for referring to a row
that failed to insert.
Upsert clauses have an additional, special argument for referring to a row that failed to insert.

```swift
@Row {
Expand All @@ -425,8 +424,8 @@ that failed to insert.
} onConflict: {
$0.title
} doUpdate: {
$0.isCompleted = $0.excluded.isCompleted
$0.priority = $0.excluded.priority
$0.isCompleted = $1.isCompleted
$0.priority = $1.priority
}
```
}
Expand Down Expand Up @@ -460,7 +459,6 @@ that failed to insert.

### Inserting drafts

- ``PrimaryKeyedTable/insert(or:_:values:onConflictDoUpdate:where:)``
- ``PrimaryKeyedTable/upsert(or:values:)``

### Inserting from a select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ Explore the full list of operators below.
- ``QueryExpression/+(_:_:)``
- ``QueryExpression/like(_:escape:)``
- ``QueryExpression/glob(_:)``
- ``QueryExpression/match(_:)``
- ``QueryExpression/hasPrefix(_:)``
- ``QueryExpression/hasSuffix(_:)``
- ``QueryExpression/contains(_:)``
Expand All @@ -128,7 +127,7 @@ Explore the full list of operators below.

- ``QueryExpression/in(_:)``
- ``Statement/contains(_:)``
- ``Statement/exists()``
- ``PartialSelectStatement/exists()``
- ``Swift/Array``
- ``Swift/ClosedRange``

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension Reminder.TableColumns {
```

Then you can use these helpers when building a query. For example, you can use
``PrimaryKeyedTableDefinition/count(filter:)`` to count the number of past due, current and
``PrimaryKeyedTableDefinition/count(distinct:filter:)`` to count the number of past due, current and
scheduled reminders in one single query like so:

@Row {
Expand Down Expand Up @@ -409,8 +409,8 @@ struct Row {

This allows the query to serialize the associated rows into JSON, which are then deserialized into
a `Row` type. To construct such a query you can use the
``PrimaryKeyedTableDefinition/jsonGroupArray(order:filter:)`` property that is defined on the
columns of [primary keyed tables](<doc:PrimaryKeyedTables>):
``PrimaryKeyedTableDefinition/jsonGroupArray(distinct:order:filter:)`` property that is defined on
the columns of [primary keyed tables](<doc:PrimaryKeyedTables>):

```swift
RemindersList
Expand Down Expand Up @@ -471,8 +471,8 @@ RemindersList
.select {
Row.Columns(
remindersList: $0,
milestones: $1.jsonGroupArray(isDistinct: true),
reminders: $2.jsonGroupArray(isDistinct: true)
milestones: $1.jsonGroupArray(distinct: true),
reminders: $2.jsonGroupArray(distinct: true)
)
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ Reminder.delete(reminder)

- ``Draft``
- ``find(_:)``
- ``insert(or:_:values:onConflict:where:doUpdate:where:)``
- ``insert(or:_:values:onConflictDoUpdate:where:)``
- ``update(or:_:)``
- ``upsert(or:values:)``
- ``delete(_:)``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
### JSON functions

- ``jsonArrayLength()``
- ``jsonGroupArray(order:filter:)``
- ``jsonObject()``
- ``jsonGroupArray(distinct:order:filter:)``
- ``TableDefinition/jsonObject()``
- ``jsonPatch(_:)``

### Optionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ reading to learn more about building SQL with StructuredQueries.

### Advanced

- <doc:FullTextSearch>
- <doc:Integration>
5 changes: 4 additions & 1 deletion Sources/StructuredQueriesCore/PrimaryKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ extension TableDefinition where QueryValue: TableDraft {
extension PrimaryKeyedTableDefinition {
/// A query expression representing the number of rows in this table.
///
/// - Parameter filter: A `FILTER` clause to apply to the aggregation.
/// - Parameters:
/// - isDistinct: Whether or not to include a `DISTINCT` clause, which filters duplicates from
/// the aggregation.
/// - filter: A `FILTER` clause to apply to the aggregation.
/// - Returns: An expression representing the number of rows in this table.
public func count(
distinct isDistinct: Bool = false,
Expand Down
6 changes: 3 additions & 3 deletions Sources/StructuredQueriesCore/SQLite/JSONFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension QueryExpression where QueryValue: Codable & QueryBindable {
/// - filter: A `FILTER` clause to apply to the aggregation.
/// - Returns: A JSON array aggregate of this expression.
public func jsonGroupArray(
isDistinct: Bool = false,
distinct isDistinct: Bool = false,
order: (some QueryExpression)? = Bool?.none,
filter: (some QueryExpression<Bool>)? = Bool?.none
) -> some QueryExpression<[QueryValue].JSONRepresentation> {
Expand Down Expand Up @@ -108,7 +108,7 @@ extension PrimaryKeyedTableDefinition where QueryValue: Codable {
/// - filter: A `FILTER` clause to apply to the aggregation.
/// - Returns: A JSON array aggregate of this table.
public func jsonGroupArray(
isDistinct: Bool = false,
distinct isDistinct: Bool = false,
order: (some QueryExpression)? = Bool?.none,
filter: (some QueryExpression<Bool>)? = Bool?.none
) -> some QueryExpression<[QueryValue].JSONRepresentation> {
Expand Down Expand Up @@ -174,7 +174,7 @@ extension PrimaryKeyedTableDefinition where QueryValue: _OptionalProtocol & Coda
/// - filter: A `FILTER` clause to apply to the aggregation.
/// - Returns: A JSON array aggregate of this table.
public func jsonGroupArray<Wrapped: Codable>(
isDistinct: Bool = false,
distinct isDistinct: Bool = false,
order: (some QueryExpression)? = Bool?.none,
filter: (some QueryExpression<Bool>)? = Bool?.none
) -> some QueryExpression<[Wrapped].JSONRepresentation>
Expand Down
6 changes: 3 additions & 3 deletions Tests/StructuredQueriesTests/JSONFunctionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension SnapshotTests {
@Test func jsonGroupArrayDisctinct() {
assertQuery(
Reminder.select {
$0.priority.jsonGroupArray(isDistinct: true)
$0.priority.jsonGroupArray(distinct: true)
}
) {
"""
Expand Down Expand Up @@ -221,8 +221,8 @@ extension SnapshotTests {
.select {
RemindersListRow.Columns(
remindersList: $0,
milestones: $1.jsonGroupArray(isDistinct: true),
reminders: $2.jsonGroupArray(isDistinct: true)
milestones: $1.jsonGroupArray(distinct: true),
reminders: $2.jsonGroupArray(distinct: true)
)
}
.limit(1)
Expand Down