Skip to content

Commit 247ed00

Browse files
authored
sql row protocol updates (#251)
1 parent 3650732 commit 247ed00

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Sources/MySQLKit/MySQLDatabase.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,26 @@ public struct MySQLConnectionSource: ConnectionPoolSource {
9191

9292
extension MySQLConnection: ConnectionPoolItem { }
9393

94+
struct MissingColumn: Error {
95+
let column: String
96+
}
97+
9498
extension MySQLRow: SQLRow {
99+
public var allColumns: [String] {
100+
self.columnDefinitions.map { $0.name }
101+
}
102+
103+
public func contains(column: String) -> Bool {
104+
self.columnDefinitions.contains { $0.name == column }
105+
}
106+
107+
public func decodeNil(column: String) throws -> Bool {
108+
self.column(column) == nil
109+
}
110+
95111
public func decode<D>(column: String, as type: D.Type) throws -> D where D : Decodable {
96112
guard let data = self.column(column) else {
97-
fatalError()
113+
throw MissingColumn(column: column)
98114
}
99115
return try MySQLDataDecoder().decode(D.self, from: data)
100116
}

0 commit comments

Comments
 (0)