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
I suspect the answer to this question may be no, but is there any way of replicating Serde's internally tagged enum representation in SQLX? I'm working on a project that uses the concept of 'vague dates' where the date range of an event happening may be known (e.g. 2025-11-01 to 2025-11-05), even though the exact date isn't. Internally, the existing database represents this with three fields: vague_date_type (Varchar), vague_date_start (Date), & vague_date_end (Date) - which may be prefixed if a table stores more than one Vague Date. Depending on the 'type' of Vague Date, the start and end dates may or may not be null. Storing a Vague Date will never need more than these three columns.
Ideally, I'd like to represent this structure in Rust as some form of an Enum, so that the correct fields are always enforced:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I suspect the answer to this question may be no, but is there any way of replicating Serde's internally tagged enum representation in SQLX? I'm working on a project that uses the concept of 'vague dates' where the date range of an event happening may be known (e.g. 2025-11-01 to 2025-11-05), even though the exact date isn't. Internally, the existing database represents this with three fields:
vague_date_type(Varchar),vague_date_start(Date), &vague_date_end(Date) - which may be prefixed if a table stores more than one Vague Date. Depending on the 'type' of Vague Date, the start and end dates may or may not be null. Storing a Vague Date will never need more than these three columns.Ideally, I'd like to represent this structure in Rust as some form of an Enum, so that the correct fields are always enforced:
Is there any way of performing this conversion using sqlx's traits? Or would I have to use an intermediate struct and
TryFrom?Beta Was this translation helpful? Give feedback.
All reactions