Skip to content

Commit fa5626e

Browse files
committed
Change column config to .column(body, [.unindexed]) syntax
1 parent 77a0f8e commit fa5626e

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

Documentation/Index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ let subject = Expression<String>("subject")
14071407
let body = Expression<String>("body")
14081408
let config = FTS4Config()
14091409
.column(subject)
1410-
.column(body, indexed: false)
1410+
.column(body, [.unindexed])
14111411
.languageId("lid")
14121412
.order(.Desc)
14131413

SQLite/Extensions/FTS4.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,21 @@ extension Connection {
158158
/// Configuration options shared between the [FTS4](https://www.sqlite.org/fts3.html) and
159159
/// [FTS5](https://www.sqlite.org/fts5.html) extensions.
160160
public class FTSConfig {
161-
typealias ColumnDefinition = (Expressible, Bool)
161+
public enum ColumnOption {
162+
/// [The notindexed= option](https://www.sqlite.org/fts3.html#section_6_5)
163+
case unindexed
164+
}
165+
166+
typealias ColumnDefinition = (Expressible, options: [ColumnOption])
162167
var columnDefinitions = [ColumnDefinition]()
163168
var tokenizer: Tokenizer?
164169
var prefixes = [Int]()
165170
var externalContentSchema: SchemaType?
166171
var isContentless: Bool = false
167172

168-
/// Adds an indexed column definition
169-
public func column(column: Expressible) -> Self {
170-
return self.column(column, indexed: true)
171-
}
172-
173173
/// Adds a column definition
174-
public func column(column: Expressible, indexed: Bool) -> Self {
175-
self.columnDefinitions.append((column, indexed))
174+
public func column(column: Expressible, _ options: [ColumnOption] = []) -> Self {
175+
self.columnDefinitions.append((column, options))
176176
return self
177177
}
178178

@@ -329,8 +329,8 @@ public class FTS4Config : FTSConfig {
329329

330330
override func options() -> Options {
331331
var options = super.options()
332-
for notIndexedColumn in (columnDefinitions.filter { !$0.1 }.map { $0.0 }) {
333-
options.append("notindexed", value: notIndexedColumn)
332+
for (column, _) in (columnDefinitions.filter { $0.options.contains(.unindexed) }) {
333+
options.append("notindexed", value: column)
334334
}
335335
options.append("languageid", value: languageId)
336336
options.append("compress", value: compressFunction)

SQLite/Extensions/FTS5.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public class FTS5Config : FTSConfig {
8787

8888
override func formatColumnDefinitions() -> [Expressible] {
8989
return columnDefinitions.map { definition in
90-
if definition.1 {
91-
return definition.0
92-
} else {
90+
if definition.options.contains(.unindexed) {
9391
return " ".join([definition.0, Expression<Void>(literal: "UNINDEXED")])
92+
} else {
93+
return definition.0
9494
}
9595
}
9696
}

SQLiteTests/FTS4Tests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class FTS4ConfigTests : XCTestCase {
7373
func test_config_unindexed_column() {
7474
XCTAssertEqual(
7575
"CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(\"string\", notindexed=\"string\")",
76-
sql(config.column(string, indexed: false)))
76+
sql(config.column(string, [.unindexed])))
7777
}
7878

7979
func test_external_content_view() {
@@ -160,8 +160,8 @@ class FTS4ConfigTests : XCTestCase {
160160
sql(config
161161
.tokenizer(.Porter)
162162
.column(int)
163-
.column(string, indexed: false)
164-
.column(date, indexed: false)
163+
.column(string, [.unindexed])
164+
.column(date, [.unindexed])
165165
.externalContent(table)
166166
.matchInfo(.FTS3)
167167
.languageId("lid")

SQLiteTests/FTS5Tests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FTS5Tests: XCTestCase {
3030
func test_config_unindexed_column() {
3131
XCTAssertEqual(
3232
"CREATE VIRTUAL TABLE \"virtual_table\" USING fts5(\"string\" UNINDEXED)",
33-
sql(config.column(string, indexed: false)))
33+
sql(config.column(string, [.unindexed])))
3434
}
3535

3636
func test_external_content_table() {
@@ -111,8 +111,8 @@ class FTS5Tests: XCTestCase {
111111
sql(config
112112
.tokenizer(.Porter)
113113
.column(int)
114-
.column(string, indexed: false)
115-
.column(date, indexed: false)
114+
.column(string, [.unindexed])
115+
.column(date, [.unindexed])
116116
.externalContent(table)
117117
.prefix([2, 4]))
118118
)

0 commit comments

Comments
 (0)