You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you run try db.run(table.filter(id == desiredID).update(modelObject)) where modelObject is a Codable struct containing an optional value where the corresponding column is defined as nullable, the SQL generated will not include the set to null as expected.
Executing the update with the above struct where end_date is nil produces the following SQL UPDATE "allocations" SET "amount" = 60.0, "note" = 'Electric', "strategy" = 'Monthly', "tag_id" = 4, "start_date" = '2018-08-01T07:00:00.000' WHERE ("id" = 5)
which excludes the end_date column set to NULL as I'd expect.
The text was updated successfully, but these errors were encountered:
It seems like in Coding.swift the methods of KeyedEncodingContainerProtocol for encoding optional values were excluded. To be honest, they are kind of non-intuitive. I don't understand why there is a separate encodeNil if it is not going to be used when optional types are indeed nil. Either way, adding the following into that file solved the issue for me:
...func encodeIfPresent(_ value:Int?, forKey key:MyKey)throws{guardlet value = value else{tryencodeNil(forKey: key)return}tryencode(value, forKey: key)}func encodeIfPresent(_ value:String?, forKey key:MyKey)throws{guardlet value = value else{tryencodeNil(forKey: key)return}tryencode(value, forKey: key)}...
Build Information
General guidelines
If you run
try db.run(table.filter(id == desiredID).update(modelObject))
wheremodelObject
is aCodable
struct containing an optional value where the corresponding column is defined as nullable, the SQL generated will not include the set to null as expected.Example:
Executing the update with the above struct where
end_date
is nil produces the following SQLUPDATE "allocations" SET "amount" = 60.0, "note" = 'Electric', "strategy" = 'Monthly', "tag_id" = 4, "start_date" = '2018-08-01T07:00:00.000' WHERE ("id" = 5)
which excludes the
end_date
column set to NULL as I'd expect.The text was updated successfully, but these errors were encountered: