Skip to content

Commit

Permalink
sql row protocol updates (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Dec 13, 2019
1 parent f25b68e commit 9f3a7fb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion 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<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
}

0 comments on commit 9f3a7fb

Please sign in to comment.