Skip to content

Commit e7c2592

Browse files
committed
Fix copypasta
1 parent 3023a1f commit e7c2592

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Sources/SQLite/Typed/Coding.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,19 +495,22 @@ private class SQLiteDecoder: Decoder {
495495
try? row.get(Expression(key.stringValue))
496496
}
497497

498-
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T? where T: Swift.Decodable {
498+
func decodeIfPresent<T>(_ type: T.Type, forKey key: Key) throws -> T? where T: Swift.Decodable {
499499
switch type {
500500
case is Data.Type:
501-
let data = try row.get(Expression<Data>(key.stringValue))
502-
return data as? T
501+
if let data = try? row.get(Expression<Data>(key.stringValue)) {
502+
return data as? T
503+
}
503504
case is Date.Type:
504-
let date = try row.get(Expression<Date>(key.stringValue))
505-
return date as? T
505+
if let date = try? row.get(Expression<Date>(key.stringValue)) {
506+
return date as? T
507+
}
506508
case is UUID.Type:
507-
let uuid = try row.get(Expression<UUID>(key.stringValue))
508-
return uuid as? T
509+
if let uuid = try? row.get(Expression<UUID>(key.stringValue)) {
510+
return uuid as? T
511+
}
509512
default:
510-
guard let JSONString = try row.get(Expression<String?>(key.stringValue)) else {
513+
guard let JSONString = try? row.get(Expression<String?>(key.stringValue)) else {
511514
throw DecodingError.typeMismatch(type, DecodingError.Context(codingPath: codingPath,
512515
debugDescription: "an unsupported type was found"))
513516
}

0 commit comments

Comments
 (0)