Skip to content

Commit 194d99a

Browse files
committed
Fix ambiguous use of description
1 parent c7154c6 commit 194d99a

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

Sources/SQLite/Extensions/FTS4.swift

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public struct Tokenizer {
117117

118118
// https://sqlite.org/fts5.html#the_experimental_trigram_tokenizer
119119
public static func Trigram(caseSensitive: Bool = false) -> Tokenizer {
120-
return Tokenizer("trigram", ["case_sensitive", caseSensitive ? "1" : "0"])
120+
Tokenizer("trigram", ["case_sensitive", caseSensitive ? "1" : "0"])
121121
}
122122

123123
public static func Custom(_ name: String) -> Tokenizer {
@@ -236,18 +236,12 @@ open class FTSConfig {
236236
}
237237
}
238238

239-
@discardableResult mutating func append(_ key: String, value: CustomStringConvertible?) -> Options {
240-
append(key, value: value?.description)
239+
@discardableResult mutating func append(_ key: String, value: String) -> Options {
240+
append(key, value: Expression<String>(value))
241241
}
242242

243-
@discardableResult mutating func append(_ key: String, value: String?) -> Options {
244-
append(key, value: value.map { Expression<String>($0) })
245-
}
246-
247-
@discardableResult mutating func append(_ key: String, value: Expressible?) -> Options {
248-
if let value = value {
249-
arguments.append("=".join([Expression<Void>(literal: key), value]))
250-
}
243+
@discardableResult mutating func append(_ key: String, value: Expressible) -> Options {
244+
arguments.append("=".join([Expression<Void>(literal: key), value]))
251245
return self
252246
}
253247
}
@@ -256,26 +250,16 @@ open class FTSConfig {
256250
/// Configuration for the [FTS4](https://www.sqlite.org/fts3.html) extension.
257251
open class FTS4Config: FTSConfig {
258252
/// [The matchinfo= option](https://www.sqlite.org/fts3.html#section_6_4)
259-
public enum MatchInfo: CustomStringConvertible {
253+
public enum MatchInfo: String {
260254
case fts3
261-
public var description: String {
262-
"fts3"
263-
}
264255
}
265256

266257
/// [FTS4 options](https://www.sqlite.org/fts3.html#fts4_options)
267-
public enum Order: CustomStringConvertible {
258+
public enum Order: String {
268259
/// Data structures are optimized for returning results in ascending order by docid (default)
269260
case asc
270261
/// FTS4 stores its data in such a way as to optimize returning results in descending order by docid.
271262
case desc
272-
273-
public var description: String {
274-
switch self {
275-
case .asc: return "asc"
276-
case .desc: return "desc"
277-
}
278-
}
279263
}
280264

281265
var compressFunction: String?
@@ -322,11 +306,21 @@ open class FTS4Config: FTSConfig {
322306
for (column, _) in (columnDefinitions.filter { $0.options.contains(.unindexed) }) {
323307
options.append("notindexed", value: column)
324308
}
325-
options.append("languageid", value: languageId)
326-
options.append("compress", value: compressFunction)
327-
options.append("uncompress", value: uncompressFunction)
328-
options.append("matchinfo", value: matchInfo)
329-
options.append("order", value: order)
309+
if let languageId = languageId {
310+
options.append("languageid", value: languageId)
311+
}
312+
if let compressFunction = compressFunction {
313+
options.append("compress", value: compressFunction)
314+
}
315+
if let uncompressFunction = uncompressFunction {
316+
options.append("uncompress", value: uncompressFunction)
317+
}
318+
if let matchInfo = matchInfo {
319+
options.append("matchinfo", value: matchInfo.rawValue)
320+
}
321+
if let order = order {
322+
options.append("order", value: order.rawValue)
323+
}
330324
return options
331325
}
332326
}

Sources/SQLite/Extensions/FTS5.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,13 @@ extension Module {
3333
/// **Note:** this is currently only applicable when using SQLite.swift together with a FTS5-enabled version
3434
/// of SQLite.
3535
open class FTS5Config: FTSConfig {
36-
public enum Detail: CustomStringConvertible {
36+
public enum Detail: String {
3737
/// store rowid, column number, term offset
3838
case full
3939
/// store rowid, column number
4040
case column
4141
/// store rowid
4242
case none
43-
44-
public var description: String {
45-
switch self {
46-
case .full: return "full"
47-
case .column: return "column"
48-
case .none: return "none"
49-
}
50-
}
5143
}
5244

5345
var detail: Detail?
@@ -77,11 +69,15 @@ open class FTS5Config: FTSConfig {
7769

7870
override func options() -> Options {
7971
var options = super.options()
80-
options.append("content_rowid", value: contentRowId)
72+
if let contentRowId = contentRowId {
73+
options.append("content_rowid", value: contentRowId)
74+
}
8175
if let columnSize = columnSize {
8276
options.append("columnsize", value: Expression<Int>(value: columnSize))
8377
}
84-
options.append("detail", value: detail)
78+
if let detail = detail {
79+
options.append("detail", value: detail.rawValue)
80+
}
8581
return options
8682
}
8783

Sources/SQLite/Typed/Expression.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// THE SOFTWARE.
2323
//
2424

25-
public protocol ExpressionType: Expressible { // extensions cannot have inheritance clauses
25+
public protocol ExpressionType: Expressible, CustomStringConvertible { // extensions cannot have inheritance clauses
2626

2727
associatedtype UnderlyingType = Void
2828

@@ -47,6 +47,9 @@ extension ExpressionType {
4747
self.init(expression.template, expression.bindings)
4848
}
4949

50+
public var description: String {
51+
asSQL()
52+
}
5053
}
5154

5255
/// An `Expression` represents a raw SQL fragment and any associated bindings.
@@ -64,16 +67,13 @@ public struct Expression<Datatype>: ExpressionType {
6467

6568
}
6669

67-
public protocol Expressible: CustomStringConvertible {
70+
public protocol Expressible {
6871

6972
var expression: Expression<Void> { get }
7073

7174
}
7275

7376
extension Expressible {
74-
public var description: String {
75-
asSQL()
76-
}
7777

7878
// naïve compiler for statements that can’t be bound, e.g., CREATE TABLE
7979
func asSQL() -> String {

Tests/SQLiteTests/Typed/ExpressionTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class ExpressionTests: XCTestCase {
1818
XCTAssertEqual(expression.asSQL(), expression.description)
1919
}
2020

21+
func test_builtin_unambiguously_custom_string_convertible() {
22+
let integer: Int = 45
23+
XCTAssertEqual(integer.description, "45")
24+
}
25+
2126
func test_init_literal() {
2227
let expression = Expression<String>(literal: "literal")
2328
XCTAssertEqual(expression.template, "literal")

0 commit comments

Comments
 (0)