File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,10 @@ extension MySQLRow: SQLRow {
105
105
}
106
106
107
107
public func decodeNil( column: String ) throws -> Bool {
108
- self . column ( column) == nil
108
+ guard let data = self . column ( column) else {
109
+ return true
110
+ }
111
+ return data. buffer == nil
109
112
}
110
113
111
114
public func decode< D> ( column: String , as type: D . Type ) throws -> D where D : Decodable {
Original file line number Diff line number Diff line change @@ -8,6 +8,18 @@ class MySQLKitTests: XCTestCase {
8
8
try self . benchmark. testEnum ( )
9
9
}
10
10
11
+ func testNullDecode( ) throws {
12
+ struct Person : Codable {
13
+ let id : Int
14
+ let name : String ?
15
+ }
16
+
17
+ let rows = try self . db. raw ( " SELECT 1 as `id`, null as `name` " )
18
+ . all ( decoding: Person . self) . wait ( )
19
+ XCTAssertEqual ( rows [ 0 ] . id, 1 )
20
+ XCTAssertEqual ( rows [ 0 ] . name, nil )
21
+ }
22
+
11
23
var db : SQLDatabase {
12
24
self . connection. sql ( )
13
25
}
You can’t perform that action at this time.
0 commit comments