Skip to content

Commit c7b78f2

Browse files
authoredDec 5, 2024··
Merge pull request #1279 from dyikai/master
2 parents a95fc6d + 363141a commit c7b78f2

19 files changed

+130
-119
lines changed
 

‎Documentation/Upgrading.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- `Expression.asSQL()` is no longer available. Expressions now implement `CustomStringConvertible`,
66
where `description` returns the SQL.
7-
- `Statement.prepareRowIterator()` is now longer available. Instead, use the methods
7+
- `Statement.prepareRowIterator()` is no longer available. Instead, use the methods
88
of the same name on `Connection`.
99
- `Connection.registerTokenizer` is no longer available to register custom FTS4 tokenizers.
10+
- `Setter.asSQL()` is no longer available. Instead, Setter now implement `CustomStringConvertible`,
11+
where `description` returns the SQL.

‎Sources/SQLite/Typed/Setter.swift

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ extension Setter: Expressible {
7575

7676
}
7777

78+
extension Setter: CustomStringConvertible {
79+
public var description: String {
80+
asSQL()
81+
}
82+
}
83+
7884
public func <-<V: Value>(column: Expression<V>, value: Expression<V>) -> Setter {
7985
Setter(column: column, value: value)
8086
}

‎Tests/SQLiteTests/Core/Connection+AttachTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ConnectionAttachTests: SQLiteTestCase {
1919
try db.attach(.inMemory, as: schemaName)
2020

2121
let table = Table("attached_users", database: schemaName)
22-
let name = Expression<String>("string")
22+
let name = SQLite.Expression<String>("string")
2323

2424
// create a table, insert some data
2525
try db.run(table.create { builder in
@@ -41,7 +41,7 @@ class ConnectionAttachTests: SQLiteTestCase {
4141
try db.attach(.uri(testDb, parameters: [.mode(.readOnly)]), as: schemaName)
4242

4343
let table = Table("tests", database: schemaName)
44-
let email = Expression<String>("email")
44+
let email = SQLite.Expression<String>("email")
4545

4646
let rows = try db.prepare(table.select(email)).map { $0[email] }
4747
XCTAssertEqual(["foo@bar.com"], rows)

‎Tests/SQLiteTests/Core/CoreFunctionsTests.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class CoreFunctionsTests: XCTestCase {
1212
}
1313

1414
func test_random_generatesExpressionWithRandomFunction() {
15-
assertSQL("random()", Expression<Int64>.random())
16-
assertSQL("random()", Expression<Int>.random())
15+
assertSQL("random()", SQLite.Expression<Int64>.random())
16+
assertSQL("random()", SQLite.Expression<Int>.random())
1717
}
1818

1919
func test_length_wrapsStringExpressionWithLengthFunction() {
@@ -38,14 +38,14 @@ class CoreFunctionsTests: XCTestCase {
3838
assertSQL("(\"string\" LIKE '%\\%' ESCAPE '\\')", string.like("%\\%", escape: "\\"))
3939
assertSQL("(\"stringOptional\" LIKE '_\\_' ESCAPE '\\')", stringOptional.like("_\\_", escape: "\\"))
4040

41-
assertSQL("(\"string\" LIKE \"a\")", string.like(Expression<String>("a")))
42-
assertSQL("(\"stringOptional\" LIKE \"a\")", stringOptional.like(Expression<String>("a")))
41+
assertSQL("(\"string\" LIKE \"a\")", string.like(SQLite.Expression<String>("a")))
42+
assertSQL("(\"stringOptional\" LIKE \"a\")", stringOptional.like(SQLite.Expression<String>("a")))
4343

44-
assertSQL("(\"string\" LIKE \"a\" ESCAPE '\\')", string.like(Expression<String>("a"), escape: "\\"))
45-
assertSQL("(\"stringOptional\" LIKE \"a\" ESCAPE '\\')", stringOptional.like(Expression<String>("a"), escape: "\\"))
44+
assertSQL("(\"string\" LIKE \"a\" ESCAPE '\\')", string.like(SQLite.Expression<String>("a"), escape: "\\"))
45+
assertSQL("(\"stringOptional\" LIKE \"a\" ESCAPE '\\')", stringOptional.like(SQLite.Expression<String>("a"), escape: "\\"))
4646

47-
assertSQL("('string' LIKE \"a\")", "string".like(Expression<String>("a")))
48-
assertSQL("('string' LIKE \"a\" ESCAPE '\\')", "string".like(Expression<String>("a"), escape: "\\"))
47+
assertSQL("('string' LIKE \"a\")", "string".like(SQLite.Expression<String>("a")))
48+
assertSQL("('string' LIKE \"a\" ESCAPE '\\')", "string".like(SQLite.Expression<String>("a"), escape: "\\"))
4949
}
5050

5151
func test_glob_buildsExpressionWithGlobOperator() {

‎Tests/SQLiteTests/Core/StatementTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StatementTests: SQLiteTestCase {
2727

2828
func test_zero_sized_blob_returns_null() throws {
2929
let blobs = Table("blobs")
30-
let blobColumn = Expression<Blob>("blob_column")
30+
let blobColumn = SQLite.Expression<Blob>("blob_column")
3131
try db.run(blobs.create { $0.column(blobColumn) })
3232
try db.run(blobs.insert(blobColumn <- Blob(bytes: [])))
3333
let blobValue = try db.scalar(blobs.select(blobColumn).limit(1, offset: 0))
@@ -38,7 +38,7 @@ class StatementTests: SQLiteTestCase {
3838
let names = ["a", "b", "c"]
3939
try insertUsers(names)
4040

41-
let emailColumn = Expression<String>("email")
41+
let emailColumn = SQLite.Expression<String>("email")
4242
let statement = try db.prepare("SELECT email FROM users")
4343
let emails = try statement.prepareRowIterator().map { $0[emailColumn] }
4444

‎Tests/SQLiteTests/Extensions/FTS4Tests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class FTS4Tests: XCTestCase {
3535
}
3636

3737
func test_match_onVirtualTableAsExpression_compilesMatchExpression() {
38-
assertSQL("(\"virtual_table\" MATCH 'string')", virtualTable.match("string") as Expression<Bool>)
39-
assertSQL("(\"virtual_table\" MATCH \"string\")", virtualTable.match(string) as Expression<Bool>)
40-
assertSQL("(\"virtual_table\" MATCH \"stringOptional\")", virtualTable.match(stringOptional) as Expression<Bool?>)
38+
assertSQL("(\"virtual_table\" MATCH 'string')", virtualTable.match("string") as SQLite.Expression<Bool>)
39+
assertSQL("(\"virtual_table\" MATCH \"string\")", virtualTable.match(string) as SQLite.Expression<Bool>)
40+
assertSQL("(\"virtual_table\" MATCH \"stringOptional\")", virtualTable.match(stringOptional) as SQLite.Expression<Bool?>)
4141
}
4242

4343
func test_match_onVirtualTableAsQueryType_compilesMatchExpression() {

‎Tests/SQLiteTests/Extensions/FTSIntegrationTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SQLite3
1111
@testable import SQLite
1212

1313
class FTSIntegrationTests: SQLiteTestCase {
14-
let email = Expression<String>("email")
14+
let email = SQLite.Expression<String>("email")
1515
let index = VirtualTable("index")
1616

1717
private func createIndex() throws {

‎Tests/SQLiteTests/Schema/SchemaChangerTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class SchemaChangerTests: SQLiteTestCase {
9292
}
9393

9494
func test_add_column() throws {
95-
let column = Expression<String>("new_column")
95+
let column = SQLite.Expression<String>("new_column")
9696
let newColumn = ColumnDefinition(name: "new_column",
9797
type: .TEXT,
9898
nullable: true,

‎Tests/SQLiteTests/Schema/SchemaReaderTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class SchemaReaderTests: SQLiteTestCase {
163163

164164
try db.run(linkTable.create(block: { definition in
165165
definition.column(idColumn, primaryKey: .autoincrement)
166-
definition.column(testIdColumn, unique: false, check: nil, references: users, Expression<Int64>("id"))
166+
definition.column(testIdColumn, unique: false, check: nil, references: users, SQLite.Expression<Int64>("id"))
167167
}))
168168

169169
let foreignKeys = try schemaReader.foreignKeys(table: "test_links")
@@ -238,7 +238,7 @@ class SchemaReaderTests: SQLiteTestCase {
238238
}
239239

240240
func test_objectDefinitions_indexes() throws {
241-
let emailIndex = users.createIndex(Expression<String>("email"), unique: false, ifNotExists: true)
241+
let emailIndex = users.createIndex(SQLite.Expression<String>("email"), unique: false, ifNotExists: true)
242242
try db.run(emailIndex)
243243

244244
let indexes = try schemaReader.objectDefinitions(type: .index)

‎Tests/SQLiteTests/TestHelpers.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,29 @@ class SQLiteTestCase: XCTestCase {
7474

7575
}
7676

77-
let bool = Expression<Bool>("bool")
78-
let boolOptional = Expression<Bool?>("boolOptional")
77+
let bool = SQLite.Expression<Bool>("bool")
78+
let boolOptional = SQLite.Expression<Bool?>("boolOptional")
7979

80-
let data = Expression<Blob>("blob")
81-
let dataOptional = Expression<Blob?>("blobOptional")
80+
let data = SQLite.Expression<Blob>("blob")
81+
let dataOptional = SQLite.Expression<Blob?>("blobOptional")
8282

83-
let date = Expression<Date>("date")
84-
let dateOptional = Expression<Date?>("dateOptional")
83+
let date = SQLite.Expression<Date>("date")
84+
let dateOptional = SQLite.Expression<Date?>("dateOptional")
8585

86-
let double = Expression<Double>("double")
87-
let doubleOptional = Expression<Double?>("doubleOptional")
86+
let double = SQLite.Expression<Double>("double")
87+
let doubleOptional = SQLite.Expression<Double?>("doubleOptional")
8888

89-
let int = Expression<Int>("int")
90-
let intOptional = Expression<Int?>("intOptional")
89+
let int = SQLite.Expression<Int>("int")
90+
let intOptional = SQLite.Expression<Int?>("intOptional")
9191

92-
let int64 = Expression<Int64>("int64")
93-
let int64Optional = Expression<Int64?>("int64Optional")
92+
let int64 = SQLite.Expression<Int64>("int64")
93+
let int64Optional = SQLite.Expression<Int64?>("int64Optional")
9494

95-
let string = Expression<String>("string")
96-
let stringOptional = Expression<String?>("stringOptional")
95+
let string = SQLite.Expression<String>("string")
96+
let stringOptional = SQLite.Expression<String?>("stringOptional")
9797

98-
let uuid = Expression<UUID>("uuid")
99-
let uuidOptional = Expression<UUID?>("uuidOptional")
98+
let uuid = SQLite.Expression<UUID>("uuid")
99+
let uuidOptional = SQLite.Expression<UUID?>("uuidOptional")
100100

101101
let testUUIDValue = UUID(uuidString: "E621E1F8-C36C-495A-93FC-0C247A3E6E5F")!
102102

‎Tests/SQLiteTests/Typed/CustomFunctionsTests.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import SQLite
55
#if !os(Linux)
66

77
class CustomFunctionNoArgsTests: SQLiteTestCase {
8-
typealias FunctionNoOptional = () -> Expression<String>
9-
typealias FunctionResultOptional = () -> Expression<String?>
8+
typealias FunctionNoOptional = () -> SQLite.Expression<String>
9+
typealias FunctionResultOptional = () -> SQLite.Expression<String?>
1010

1111
func testFunctionNoOptional() throws {
1212
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) {
@@ -26,10 +26,10 @@ class CustomFunctionNoArgsTests: SQLiteTestCase {
2626
}
2727

2828
class CustomFunctionWithOneArgTests: SQLiteTestCase {
29-
typealias FunctionNoOptional = (Expression<String>) -> Expression<String>
30-
typealias FunctionLeftOptional = (Expression<String?>) -> Expression<String>
31-
typealias FunctionResultOptional = (Expression<String>) -> Expression<String?>
32-
typealias FunctionLeftResultOptional = (Expression<String?>) -> Expression<String?>
29+
typealias FunctionNoOptional = (SQLite.Expression<String>) -> SQLite.Expression<String>
30+
typealias FunctionLeftOptional = (SQLite.Expression<String?>) -> SQLite.Expression<String>
31+
typealias FunctionResultOptional = (SQLite.Expression<String>) -> SQLite.Expression<String?>
32+
typealias FunctionLeftResultOptional = (SQLite.Expression<String?>) -> SQLite.Expression<String?>
3333

3434
func testFunctionNoOptional() throws {
3535
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) { a in
@@ -65,14 +65,14 @@ class CustomFunctionWithOneArgTests: SQLiteTestCase {
6565
}
6666

6767
class CustomFunctionWithTwoArgsTests: SQLiteTestCase {
68-
typealias FunctionNoOptional = (Expression<String>, Expression<String>) -> Expression<String>
69-
typealias FunctionLeftOptional = (Expression<String?>, Expression<String>) -> Expression<String>
70-
typealias FunctionRightOptional = (Expression<String>, Expression<String?>) -> Expression<String>
71-
typealias FunctionResultOptional = (Expression<String>, Expression<String>) -> Expression<String?>
72-
typealias FunctionLeftRightOptional = (Expression<String?>, Expression<String?>) -> Expression<String>
73-
typealias FunctionLeftResultOptional = (Expression<String?>, Expression<String>) -> Expression<String?>
74-
typealias FunctionRightResultOptional = (Expression<String>, Expression<String?>) -> Expression<String?>
75-
typealias FunctionLeftRightResultOptional = (Expression<String?>, Expression<String?>) -> Expression<String?>
68+
typealias FunctionNoOptional = (SQLite.Expression<String>, SQLite.Expression<String>) -> SQLite.Expression<String>
69+
typealias FunctionLeftOptional = (SQLite.Expression<String?>, SQLite.Expression<String>) -> SQLite.Expression<String>
70+
typealias FunctionRightOptional = (SQLite.Expression<String>, SQLite.Expression<String?>) -> SQLite.Expression<String>
71+
typealias FunctionResultOptional = (SQLite.Expression<String>, SQLite.Expression<String>) -> SQLite.Expression<String?>
72+
typealias FunctionLeftRightOptional = (SQLite.Expression<String?>, SQLite.Expression<String?>) -> SQLite.Expression<String>
73+
typealias FunctionLeftResultOptional = (SQLite.Expression<String?>, SQLite.Expression<String>) -> SQLite.Expression<String?>
74+
typealias FunctionRightResultOptional = (SQLite.Expression<String>, SQLite.Expression<String?>) -> SQLite.Expression<String?>
75+
typealias FunctionLeftRightResultOptional = (SQLite.Expression<String?>, SQLite.Expression<String?>) -> SQLite.Expression<String?>
7676

7777
func testNoOptional() throws {
7878
let _: FunctionNoOptional = try db.createFunction("test", deterministic: true) { a, b in

‎Tests/SQLiteTests/Typed/ExpressionTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import XCTest
44
class ExpressionTests: XCTestCase {
55

66
func test_asSQL_expression_bindings() {
7-
let expression = Expression<String>("foo ? bar", ["baz"])
7+
let expression = SQLite.Expression<String>("foo ? bar", ["baz"])
88
XCTAssertEqual(expression.asSQL(), "foo 'baz' bar")
99
}
1010

1111
func test_asSQL_expression_bindings_quoting() {
12-
let expression = Expression<String>("foo ? bar", ["'baz'"])
12+
let expression = SQLite.Expression<String>("foo ? bar", ["'baz'"])
1313
XCTAssertEqual(expression.asSQL(), "foo '''baz''' bar")
1414
}
1515

1616
func test_expression_custom_string_convertible() {
17-
let expression = Expression<String>("foo ? bar", ["baz"])
17+
let expression = SQLite.Expression<String>("foo ? bar", ["baz"])
1818
XCTAssertEqual(expression.asSQL(), expression.description)
1919
}
2020

@@ -24,12 +24,12 @@ class ExpressionTests: XCTestCase {
2424
}
2525

2626
func test_init_literal() {
27-
let expression = Expression<String>(literal: "literal")
27+
let expression = SQLite.Expression<String>(literal: "literal")
2828
XCTAssertEqual(expression.template, "literal")
2929
}
3030

3131
func test_init_identifier() {
32-
let expression = Expression<String>("identifier")
32+
let expression = SQLite.Expression<String>("identifier")
3333
XCTAssertEqual(expression.template, "\"identifier\"")
3434
}
3535
}

‎Tests/SQLiteTests/Typed/OperatorsTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class OperatorsTests: XCTestCase {
356356
}
357357

358358
func test_precedencePreserved() {
359-
let n = Expression<Int>(value: 1)
359+
let n = SQLite.Expression<Int>(value: 1)
360360
assertSQL("(((1 = 1) AND (1 = 1)) OR (1 = 1))", (n == n && n == n) || n == n)
361361
assertSQL("((1 = 1) AND ((1 = 1) OR (1 = 1)))", n == n && (n == n || n == n))
362362
}

‎Tests/SQLiteTests/Typed/QueryIntegrationTests.swift

+35-35
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import SQLite3
1212

1313
class QueryIntegrationTests: SQLiteTestCase {
1414

15-
let id = Expression<Int64>("id")
16-
let email = Expression<String>("email")
17-
let age = Expression<Int>("age")
15+
let id = SQLite.Expression<Int64>("id")
16+
let email = SQLite.Expression<String>("email")
17+
let age = SQLite.Expression<Int>("age")
1818

1919
override func setUpWithError() throws {
2020
try super.setUpWithError()
@@ -24,7 +24,7 @@ class QueryIntegrationTests: SQLiteTestCase {
2424
// MARK: -
2525

2626
func test_select() throws {
27-
let managerId = Expression<Int64>("manager_id")
27+
let managerId = SQLite.Expression<Int64>("manager_id")
2828
let managers = users.alias("managers")
2929

3030
let alice = try db.run(users.insert(email <- "alice@example.com"))
@@ -39,7 +39,7 @@ class QueryIntegrationTests: SQLiteTestCase {
3939
let names = ["a", "b", "c"]
4040
try insertUsers(names)
4141

42-
let emailColumn = Expression<String>("email")
42+
let emailColumn = SQLite.Expression<String>("email")
4343
let emails = try db.prepareRowIterator(users).map { $0[emailColumn] }
4444

4545
XCTAssertEqual(names.map({ "\($0)@example.com" }), emails.sorted())
@@ -55,7 +55,7 @@ class QueryIntegrationTests: SQLiteTestCase {
5555
}
5656

5757
func test_select_optional() throws {
58-
let managerId = Expression<Int64?>("manager_id")
58+
let managerId = SQLite.Expression<Int64?>("manager_id")
5959
let managers = users.alias("managers")
6060

6161
let alice = try db.run(users.insert(email <- "alice@example.com"))
@@ -69,15 +69,15 @@ class QueryIntegrationTests: SQLiteTestCase {
6969
func test_select_codable() throws {
7070
let table = Table("codable")
7171
try db.run(table.create { builder in
72-
builder.column(Expression<Int>("int"))
73-
builder.column(Expression<String>("string"))
74-
builder.column(Expression<Bool>("bool"))
75-
builder.column(Expression<Double>("float"))
76-
builder.column(Expression<Double>("double"))
77-
builder.column(Expression<Date>("date"))
78-
builder.column(Expression<UUID>("uuid"))
79-
builder.column(Expression<String?>("optional"))
80-
builder.column(Expression<Data>("sub"))
72+
builder.column(SQLite.Expression<Int>("int"))
73+
builder.column(SQLite.Expression<String>("string"))
74+
builder.column(SQLite.Expression<Bool>("bool"))
75+
builder.column(SQLite.Expression<Double>("float"))
76+
builder.column(SQLite.Expression<Double>("double"))
77+
builder.column(SQLite.Expression<Date>("date"))
78+
builder.column(SQLite.Expression<UUID>("uuid"))
79+
builder.column(SQLite.Expression<String?>("optional"))
80+
builder.column(SQLite.Expression<Data>("sub"))
8181
})
8282

8383
let value1 = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
@@ -133,13 +133,13 @@ class QueryIntegrationTests: SQLiteTestCase {
133133
func test_insert_many_encodables() throws {
134134
let table = Table("codable")
135135
try db.run(table.create { builder in
136-
builder.column(Expression<Int?>("int"))
137-
builder.column(Expression<String?>("string"))
138-
builder.column(Expression<Bool?>("bool"))
139-
builder.column(Expression<Double?>("float"))
140-
builder.column(Expression<Double?>("double"))
141-
builder.column(Expression<Date?>("date"))
142-
builder.column(Expression<UUID?>("uuid"))
136+
builder.column(SQLite.Expression<Int?>("int"))
137+
builder.column(SQLite.Expression<String?>("string"))
138+
builder.column(SQLite.Expression<Bool?>("bool"))
139+
builder.column(SQLite.Expression<Double?>("float"))
140+
builder.column(SQLite.Expression<Double?>("double"))
141+
builder.column(SQLite.Expression<Date?>("date"))
142+
builder.column(SQLite.Expression<UUID?>("uuid"))
143143
})
144144

145145
let value1 = TestOptionalCodable(int: 5, string: "6", bool: true, float: 7, double: 8,
@@ -161,9 +161,9 @@ class QueryIntegrationTests: SQLiteTestCase {
161161

162162
let table = Table("custom_codable")
163163
try db.run(table.create { builder in
164-
builder.column(Expression<Int?>("myInt"))
165-
builder.column(Expression<String?>("myString"))
166-
builder.column(Expression<String?>("myOptionalArray"))
164+
builder.column(SQLite.Expression<Int?>("myInt"))
165+
builder.column(SQLite.Expression<String?>("myString"))
166+
builder.column(SQLite.Expression<String?>("myOptionalArray"))
167167
})
168168

169169
let customType = TestTypeWithOptionalArray(myInt: 13, myString: "foo", myOptionalArray: [1, 2, 3])
@@ -216,22 +216,22 @@ class QueryIntegrationTests: SQLiteTestCase {
216216
let actualIDs = try db.prepare(query1.union(query2)).map { $0[id] }
217217
XCTAssertEqual(expectedIDs, actualIDs)
218218

219-
let query3 = users.select(users[*], Expression<Int>(literal: "1 AS weight")).filter(email == "sally@example.com")
220-
let query4 = users.select(users[*], Expression<Int>(literal: "2 AS weight")).filter(email == "alice@example.com")
219+
let query3 = users.select(users[*], SQLite.Expression<Int>(literal: "1 AS weight")).filter(email == "sally@example.com")
220+
let query4 = users.select(users[*], SQLite.Expression<Int>(literal: "2 AS weight")).filter(email == "alice@example.com")
221221

222-
let sql = query3.union(query4).order(Expression<Int>(literal: "weight")).asSQL()
222+
let sql = query3.union(query4).order(SQLite.Expression<Int>(literal: "weight")).asSQL()
223223
XCTAssertEqual(sql,
224224
"""
225225
SELECT "users".*, 1 AS weight FROM "users" WHERE ("email" = 'sally@example.com') UNION \
226226
SELECT "users".*, 2 AS weight FROM "users" WHERE ("email" = 'alice@example.com') ORDER BY weight
227227
""")
228228

229-
let orderedIDs = try db.prepare(query3.union(query4).order(Expression<Int>(literal: "weight"), email)).map { $0[id] }
229+
let orderedIDs = try db.prepare(query3.union(query4).order(SQLite.Expression<Int>(literal: "weight"), email)).map { $0[id] }
230230
XCTAssertEqual(Array(expectedIDs.reversed()), orderedIDs)
231231
}
232232

233233
func test_no_such_column() throws {
234-
let doesNotExist = Expression<String>("doesNotExist")
234+
let doesNotExist = SQLite.Expression<String>("doesNotExist")
235235
try insertUser("alice")
236236
let row = try db.pluck(users.filter(email == "alice@example.com"))!
237237

@@ -272,15 +272,15 @@ class QueryIntegrationTests: SQLiteTestCase {
272272
// https://github.com/stephencelis/SQLite.swift/issues/285
273273
func test_order_by_random() throws {
274274
try insertUsers(["a", "b", "c'"])
275-
let result = Array(try db.prepare(users.select(email).order(Expression<Int>.random()).limit(1)))
275+
let result = Array(try db.prepare(users.select(email).order(SQLite.Expression<Int>.random()).limit(1)))
276276
XCTAssertEqual(1, result.count)
277277
}
278278

279279
func test_with_recursive() throws {
280280
let nodes = Table("nodes")
281-
let id = Expression<Int64>("id")
282-
let parent = Expression<Int64?>("parent")
283-
let value = Expression<Int64>("value")
281+
let id = SQLite.Expression<Int64>("id")
282+
let parent = SQLite.Expression<Int64?>("parent")
283+
let value = SQLite.Expression<Int64>("value")
284284

285285
try db.run(nodes.create { builder in
286286
builder.column(id)
@@ -320,7 +320,7 @@ class QueryIntegrationTests: SQLiteTestCase {
320320
/// Verify that `*` is properly expanded in a SELECT statement following a WITH clause.
321321
func test_with_glob_expansion() throws {
322322
let names = Table("names")
323-
let name = Expression<String>("name")
323+
let name = SQLite.Expression<String>("name")
324324
try db.run(names.create { builder in
325325
builder.column(email)
326326
builder.column(name)

‎Tests/SQLiteTests/Typed/QueryTests.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import SQLite3
1313
class QueryTests: XCTestCase {
1414

1515
let users = Table("users")
16-
let id = Expression<Int64>("id")
17-
let email = Expression<String>("email")
18-
let age = Expression<Int?>("age")
19-
let admin = Expression<Bool>("admin")
20-
let optionalAdmin = Expression<Bool?>("admin")
16+
let id = SQLite.Expression<Int64>("id")
17+
let email = SQLite.Expression<String>("email")
18+
let age = SQLite.Expression<Int?>("age")
19+
let admin = SQLite.Expression<Bool>("admin")
20+
let optionalAdmin = SQLite.Expression<Bool?>("admin")
2121

2222
let posts = Table("posts")
23-
let userId = Expression<Int64>("user_id")
24-
let categoryId = Expression<Int64>("category_id")
25-
let published = Expression<Bool>("published")
23+
let userId = SQLite.Expression<Int64>("user_id")
24+
let categoryId = SQLite.Expression<Int64>("category_id")
25+
let published = SQLite.Expression<Bool>("published")
2626

2727
let categories = Table("categories")
28-
let tag = Expression<String>("tag")
28+
let tag = SQLite.Expression<String>("tag")
2929

3030
func test_select_withExpression_compilesSelectClause() {
3131
assertSQL("SELECT \"email\" FROM \"users\"", users.select(email))
@@ -217,7 +217,7 @@ class QueryTests: XCTestCase {
217217
}
218218

219219
func test_alias_aliasesTable() {
220-
let managerId = Expression<Int64>("manager_id")
220+
let managerId = SQLite.Expression<Int64>("manager_id")
221221

222222
let managers = users.alias("managers")
223223

@@ -422,7 +422,7 @@ class QueryTests: XCTestCase {
422422

423423
func test_upsert_encodable() throws {
424424
let emails = Table("emails")
425-
let string = Expression<String>("string")
425+
let string = SQLite.Expression<String>("string")
426426
let value = TestCodable(int: 1, string: "2", bool: true, float: 3, double: 4,
427427
date: Date(timeIntervalSince1970: 0), uuid: testUUIDValue, optional: nil, sub: nil)
428428
let insert = try emails.upsert(value, onConflictOf: string)

‎Tests/SQLiteTests/Typed/RowTests.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@ class RowTests: XCTestCase {
55

66
public func test_get_value() throws {
77
let row = Row(["\"foo\"": 0], ["value"])
8-
let result = try row.get(Expression<String>("foo"))
8+
let result = try row.get(SQLite.Expression<String>("foo"))
99

1010
XCTAssertEqual("value", result)
1111
}
1212

1313
public func test_get_value_subscript() {
1414
let row = Row(["\"foo\"": 0], ["value"])
15-
let result = row[Expression<String>("foo")]
15+
let result = row[SQLite.Expression<String>("foo")]
1616

1717
XCTAssertEqual("value", result)
1818
}
1919

2020
public func test_get_value_optional() throws {
2121
let row = Row(["\"foo\"": 0], ["value"])
22-
let result = try row.get(Expression<String?>("foo"))
22+
let result = try row.get(SQLite.Expression<String?>("foo"))
2323

2424
XCTAssertEqual("value", result)
2525
}
2626

2727
public func test_get_value_optional_subscript() {
2828
let row = Row(["\"foo\"": 0], ["value"])
29-
let result = row[Expression<String?>("foo")]
29+
let result = row[SQLite.Expression<String?>("foo")]
3030

3131
XCTAssertEqual("value", result)
3232
}
3333

3434
public func test_get_value_optional_nil() throws {
3535
let row = Row(["\"foo\"": 0], [nil])
36-
let result = try row.get(Expression<String?>("foo"))
36+
let result = try row.get(SQLite.Expression<String?>("foo"))
3737

3838
XCTAssertNil(result)
3939
}
4040

4141
public func test_get_value_optional_nil_subscript() {
4242
let row = Row(["\"foo\"": 0], [nil])
43-
let result = row[Expression<String?>("foo")]
43+
let result = row[SQLite.Expression<String?>("foo")]
4444

4545
XCTAssertNil(result)
4646
}
4747

4848
public func test_get_type_mismatch_throws_unexpected_null_value() {
4949
let row = Row(["\"foo\"": 0], ["value"])
50-
XCTAssertThrowsError(try row.get(Expression<Int>("foo"))) { error in
50+
XCTAssertThrowsError(try row.get(SQLite.Expression<Int>("foo"))) { error in
5151
if case QueryError.unexpectedNullValue(let name) = error {
5252
XCTAssertEqual("\"foo\"", name)
5353
} else {
@@ -58,13 +58,13 @@ class RowTests: XCTestCase {
5858

5959
public func test_get_type_mismatch_optional_returns_nil() throws {
6060
let row = Row(["\"foo\"": 0], ["value"])
61-
let result = try row.get(Expression<Int?>("foo"))
61+
let result = try row.get(SQLite.Expression<Int?>("foo"))
6262
XCTAssertNil(result)
6363
}
6464

6565
public func test_get_non_existent_column_throws_no_such_column() {
6666
let row = Row(["\"foo\"": 0], ["value"])
67-
XCTAssertThrowsError(try row.get(Expression<Int>("bar"))) { error in
67+
XCTAssertThrowsError(try row.get(SQLite.Expression<Int>("bar"))) { error in
6868
if case QueryError.noSuchColumn(let name, let columns) = error {
6969
XCTAssertEqual("\"bar\"", name)
7070
XCTAssertEqual(["\"foo\""], columns)
@@ -76,7 +76,7 @@ class RowTests: XCTestCase {
7676

7777
public func test_get_ambiguous_column_throws() {
7878
let row = Row(["table1.\"foo\"": 0, "table2.\"foo\"": 1], ["value"])
79-
XCTAssertThrowsError(try row.get(Expression<Int>("foo"))) { error in
79+
XCTAssertThrowsError(try row.get(SQLite.Expression<Int>("foo"))) { error in
8080
if case QueryError.ambiguousColumn(let name, let columns) = error {
8181
XCTAssertEqual("\"foo\"", name)
8282
XCTAssertEqual(["table1.\"foo\"", "table2.\"foo\""], columns.sorted())
@@ -107,7 +107,7 @@ class RowTests: XCTestCase {
107107
}
108108

109109
let row = Row(["\"foo\"": 0], [Blob(bytes: [])])
110-
XCTAssertThrowsError(try row.get(Expression<MyType>("foo"))) { error in
110+
XCTAssertThrowsError(try row.get(SQLite.Expression<MyType>("foo"))) { error in
111111
if case MyType.MyError.failed = error {
112112
XCTAssertTrue(true)
113113
} else {

‎Tests/SQLiteTests/Typed/SelectTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class SelectTests: SQLiteTestCase {
2424
let usersData = Table("users_name")
2525
let users = Table("users")
2626

27-
let name = Expression<String>("name")
28-
let id = Expression<Int64>("id")
29-
let userID = Expression<Int64>("user_id")
30-
let email = Expression<String>("email")
27+
let name = SQLite.Expression<String>("name")
28+
let id = SQLite.Expression<Int64>("id")
29+
let userID = SQLite.Expression<Int64>("user_id")
30+
let email = SQLite.Expression<String>("email")
3131

3232
try insertUser("Joey")
3333
try db.run(usersData.insert(

‎Tests/SQLiteTests/Typed/SetterTests.swift

+3
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,7 @@ class SetterTests: XCTestCase {
134134
assertSQL("\"intOptional\" = (\"intOptional\" - 1)", intOptional--)
135135
}
136136

137+
func test_setter_custom_string_convertible() {
138+
XCTAssertEqual("\"int\" = \"int\"", (int <- int).description)
139+
}
137140
}

‎Tests/SQLiteTests/Typed/WindowFunctionsTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class WindowFunctionsTests: XCTestCase {
3434
func test_lag_wrapsExpressionWithOverClause() {
3535
assertSQL("lag(\"int\", 0) OVER (ORDER BY \"int\" DESC)", int.lag(int.desc))
3636
assertSQL("lag(\"int\", 7) OVER (ORDER BY \"int\" DESC)", int.lag(offset: 7, int.desc))
37-
assertSQL("lag(\"int\", 1, 3) OVER (ORDER BY \"int\" DESC)", int.lag(offset: 1, default: Expression<Int>(value: 3), int.desc))
37+
assertSQL("lag(\"int\", 1, 3) OVER (ORDER BY \"int\" DESC)", int.lag(offset: 1, default: SQLite.Expression<Int>(value: 3), int.desc))
3838
}
3939

4040
func test_lead_wrapsExpressionWithOverClause() {
4141
assertSQL("lead(\"int\", 0) OVER (ORDER BY \"int\" DESC)", int.lead(int.desc))
4242
assertSQL("lead(\"int\", 7) OVER (ORDER BY \"int\" DESC)", int.lead(offset: 7, int.desc))
43-
assertSQL("lead(\"int\", 1, 3) OVER (ORDER BY \"int\" DESC)", int.lead(offset: 1, default: Expression<Int>(value: 3), int.desc))
43+
assertSQL("lead(\"int\", 1, 3) OVER (ORDER BY \"int\" DESC)", int.lead(offset: 1, default: SQLite.Expression<Int>(value: 3), int.desc))
4444
}
4545

4646
func test_firstValue_wrapsExpressionWithOverClause() {

0 commit comments

Comments
 (0)
Please sign in to comment.