Skip to content

Commit c7b78f2

Browse files
authored
Merge pull request #1279 from dyikai/master
2 parents a95fc6d + 363141a commit c7b78f2

19 files changed

+130
-119
lines changed

Documentation/Upgrading.md

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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(["[email protected]"], rows)

Tests/SQLiteTests/Core/CoreFunctionsTests.swift

Lines changed: 8 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 16 additions & 16 deletions
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

0 commit comments

Comments
 (0)