Proposal: Support for SQLite Generated Columns #94
remimarsal
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
@remimarsal This all sounds great to us! A few thoughts:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
SQLite supports Generated Columns, which are columns whose values are automatically computed based on other columns in the same row. This is a powerful feature for enforcing data consistency and simplifying application logic by delegating computations to the database.
Currently,
swift-structured-queries
does not have a first-class way to represent these columns:INSERT
andUPDATE
statements, resulting in a "read-only column" error from SQLite.@Ephemeral
is also incorrect, as the column does exist in the database and should be included inSELECT
statements.Proposed Solution
Introduction of a new property macro,
@GeneratedColumn
, to be used within a@Table
macro.This macro would signal to the query builder that
endAt
is a column that exists for reading (SELECT
) but should be ignored for writing (INSERT
,UPDATE
).The
@GeneratedColumn
macro would be parameter-less since the database schema definition (including theGENERATED ALWAYS AS ...
expression) lives outside the Swift type definitions, typically in SQL migration files. The macro's only role is to inform the query builder of the column read-only nature.Let me know what you think, I've been experimenting with the macro and it seems to work as expected. I'm happy to open a PR !
Beta Was this translation helpful? Give feedback.
All reactions