Lighter-swift / Lighter

Swift APIs for SQLite: Type-safe down to the schema. Very, very, fast. Dependency free.
https://lighter-swift.github.io/documentation/lighter/
MIT License
458 stars 12 forks source link

SQLite Views loose type affinity w/ aggregates, workaround that #4

Open helje5 opened 2 years ago

helje5 commented 2 years ago

As soon as an aggregate function is used, SQLite seems to loose the type affinity of the expression, e.g.:

CREATE TABLE fun ( value INT );
CREATE VIEW fun_sum AS SELECT SUM(value) AS combined FROM fun;

Results in:

/// Column `combined ` (`ANY`), optional (default: `nil`).
public var combined : String?

Which isn't great.

Adding CASTs doesn't seem to help with that, the affinity is lost by the aggregate function. To fix that, we'd probably have to parse the SQL and follow the type-affinity in the expression AST. Possible but work.

helje5 commented 2 years ago

Related to issue #2