@@ -152,6 +152,33 @@ class QueryIntegrationTests: SQLiteTestCase {
152
152
XCTAssertEqual ( values. count, 2 )
153
153
}
154
154
155
+ func test_insert_custom_encodable_type( ) throws {
156
+ struct TestTypeWithOptionalArray : Codable {
157
+ var myInt : Int
158
+ var myString : String
159
+ var myOptionalArray : [ Int ] ?
160
+ }
161
+
162
+ let table = Table ( " custom_codable " )
163
+ try db. run ( table. create { builder in
164
+ builder. column ( Expression < Int ? > ( " myInt " ) )
165
+ builder. column ( Expression < String ? > ( " myString " ) )
166
+ builder. column ( Expression < String ? > ( " myOptionalArray " ) )
167
+ } )
168
+
169
+ let customType = TestTypeWithOptionalArray ( myInt: 13 , myString: " foo " , myOptionalArray: [ 1 , 2 , 3 ] )
170
+ try db. run ( table. insert ( customType) )
171
+ let rows = try db. prepare ( table)
172
+ let values : [ TestTypeWithOptionalArray ] = try rows. map ( { try $0. decode ( ) } )
173
+ XCTAssertEqual ( values. count, 1 , " return one optional custom type " )
174
+
175
+ let customTypeWithNil = TestTypeWithOptionalArray ( myInt: 123 , myString: " String " , myOptionalArray: nil )
176
+ try db. run ( table. insert ( customTypeWithNil) )
177
+ let rowsNil = try db. prepare ( table)
178
+ let valuesNil : [ TestTypeWithOptionalArray ] = try rowsNil. map ( { try $0. decode ( ) } )
179
+ XCTAssertEqual ( valuesNil. count, 2 , " return two custom objects, including one that contains a nil optional " )
180
+ }
181
+
155
182
func test_upsert( ) throws {
156
183
try XCTSkipUnless ( db. satisfiesMinimumVersion ( minor: 24 ) )
157
184
let fetchAge = { ( ) throws -> Int ? in
0 commit comments