From 9f3a7fb91c983b943edd239351ed9cd0cb75eda1 Mon Sep 17 00:00:00 2001 From: Tanner Date: Fri, 13 Dec 2019 17:04:39 -0500 Subject: [PATCH] sql row protocol updates (#66) --- Sources/SQLiteKit/SQLiteRow+SQLRow.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/SQLiteKit/SQLiteRow+SQLRow.swift b/Sources/SQLiteKit/SQLiteRow+SQLRow.swift index c7cff9e..89173c0 100644 --- a/Sources/SQLiteKit/SQLiteRow+SQLRow.swift +++ b/Sources/SQLiteKit/SQLiteRow+SQLRow.swift @@ -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(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 +}