SQLite.swift icon indicating copy to clipboard operation
SQLite.swift copied to clipboard

WIP: Demo Codable Enum issue

Open ReDetection opened this issue 3 years ago • 1 comments

This is not the MR to merge in the current, but more like an issue with submitted demo test case.

The problem: Codable Enum works fine only if saved via Encodable insert, but breaks if I insert column values directly. Compare:

try db.run(table.insert(value)) //this one will read just fine
// INSERT INTO "codable_camel_case" ("camelCaseString") VALUES ('"one"')
try db.run(table.insert(column <- .one)) //this one produces runtime error upon decode
// INSERT INTO "codable_camel_case" ("camelCaseString") VALUES ('one')

I did implement conformance to Value protocol, as you can see in the code, but it seems fromDatatypeValue() function is never used. Instead, it seems to treat it as a JSON, but the second inserted value is of course no valid JSON

ReDetection avatar Apr 14 '22 15:04 ReDetection

There's also an issue with filtering: When using a String enum as a Value type for a column, it gets wrapped in quotes (its json representation instead of the raw string), but when using it as an Expression, it is not wrapped. This causes well-typed filters to fail to match. Not sure if there's a workaround for that.

joprice avatar Nov 25 '23 21:11 joprice