-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f25b68e
commit 9f3a7fb
Showing
1 changed file
with
13 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
extension SQLiteRow: SQLRow { | ||
public var allColumns: [String] { | ||
.init(self.columns.offsets.keys) | ||
} | ||
|
||
public func decodeNil(column: String) throws -> Bool { | ||
self.columns.offsets.keys.contains(column) | ||
} | ||
|
||
public func contains(column: String) -> Bool { | ||
return self.column(column) != nil | ||
} | ||
|
||
public func decode<D>(column: String, as type: D.Type) throws -> D where D : Decodable { | ||
guard let data = self.column(column) else { | ||
fatalError("no value found for \(column)") | ||
throw MissingColumn(column: column) | ||
} | ||
return try SQLiteDataDecoder().decode(D.self, from: data) | ||
} | ||
} | ||
|
||
struct MissingColumn: Error { | ||
let column: String | ||
} |