Skip to content

Commit b715493

Browse files
Lint Fix and added test
1 parent da8d7b3 commit b715493

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Sources/SQLite/Typed/Coding.swift

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

Tests/SQLiteTests/FoundationTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,30 @@ class FoundationTests: XCTestCase {
2525
let uuid = UUID.fromDatatypeValue(string)
2626
XCTAssertEqual(UUID(uuidString: "4ABE10C9-FF12-4CD4-90C1-4B429001BAD3"), uuid)
2727
}
28+
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()
52+
}
53+
}
2854
}

Tests/SQLiteTests/TestHelpers.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ let int64Optional = Expression<Int64?>("int64Optional")
9595
let string = Expression<String>("string")
9696
let stringOptional = Expression<String?>("stringOptional")
9797

98+
let uuid = Expression<UUID>("uuid")
99+
let uuidOptional = Expression<UUID?>("uuidOptional")
100+
98101
func assertSQL(_ expression1: @autoclosure () -> String, _ expression2: @autoclosure () -> Expressible,
99102
file: StaticString = #file, line: UInt = #line) {
100103
XCTAssertEqual(expression1(), expression2().asSQL(), file: file, line: line)

0 commit comments

Comments
 (0)