Skip to content

Commit 09e8424

Browse files
used UUID.datatypeValue and moved tests
1 parent c448314 commit 09e8424

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

Sources/SQLite/Typed/Coding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private class SQLiteEncoder: Encoder {
208208
} else if let date = value as? Date {
209209
encoder.setters.append(Expression(key.stringValue) <- date.datatypeValue)
210210
} else if let uuid = value as? UUID {
211-
encoder.setters.append(Expression(key.stringValue) <- uuid.uuidString)
211+
encoder.setters.append(Expression(key.stringValue) <- uuid.datatypeValue)
212212
} else {
213213
let encoded = try JSONEncoder().encode(value)
214214
let string = String(data: encoded, encoding: .utf8)

Tests/SQLiteTests/FoundationTests.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,4 @@ class FoundationTests: XCTestCase {
2626
XCTAssertEqual(UUID(uuidString: "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3"), uuid)
2727
}
2828

29-
func testUUIDInsert() {
30-
struct Test: Codable {
31-
var uuid: UUID
32-
var string: String
33-
}
34-
let testUUID = UUID()
35-
let testValue = Test(uuid: testUUID, string: "value")
36-
let db = try! Connection(.temporary)
37-
try! db.run(table.create { t in
38-
t.column(uuid)
39-
t.column(string)
40-
}
41-
)
42-
43-
let iQuery = try! table.insert(testValue)
44-
try! db.run(iQuery)
45-
46-
let fQuery = table.filter(uuid == testUUID)
47-
if let result = try! db.pluck(fQuery) {
48-
let testValueReturned = Test(uuid: result[uuid], string: result[string])
49-
XCTAssertEqual(testUUID, testValueReturned.uuid)
50-
} else {
51-
XCTFail("Search for uuid failed")
52-
}
53-
}
5429
}

Tests/SQLiteTests/QueryTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,32 @@ class QueryTests: XCTestCase {
310310
}
311311
#endif
312312

313+
func test_insert_and_search_for_UUID() {
314+
struct Test: Codable {
315+
var uuid: UUID
316+
var string: String
317+
}
318+
let testUUID = UUID()
319+
let testValue = Test(uuid: testUUID, string: "value")
320+
let db = try! Connection(.temporary)
321+
try! db.run(table.create { t in
322+
t.column(uuid)
323+
t.column(string)
324+
}
325+
)
326+
327+
let iQuery = try! table.insert(testValue)
328+
try! db.run(iQuery)
329+
330+
let fQuery = table.filter(uuid == testUUID)
331+
if let result = try! db.pluck(fQuery) {
332+
let testValueReturned = Test(uuid: result[uuid], string: result[string])
333+
XCTAssertEqual(testUUID, testValueReturned.uuid)
334+
} else {
335+
XCTFail("Search for uuid failed")
336+
}
337+
}
338+
313339
func test_upsert_withOnConflict_compilesInsertOrOnConflictExpression() {
314340
assertSQL(
315341
"""

0 commit comments

Comments
 (0)