Store enum as jsonb
?
#2968
Unanswered
spiffytech
asked this question in
Q&A
Replies: 0 comments
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.
-
I have some data shaped like this:
With a Postgres schema like this:
What do I need to do allow sqlx to read from the database using
query_as!(MyTable, ...)
, and write a row to the database?(I'm trying to store as
jsonb
because sqlx doesn't support this data type directly, and storing arbitrary data structures asjsonb
column seems like a reasonable workaround. I also have more complicated data types I'll want to treat the same way.)If I try
derive
macros, or try setting theMyTable
field to type `Option<sqlx::types::Json>, I get errors saying enums are unsupported.I tried to manually
impl
Encode
/Decode
/Type
, but writes error out witherror returned from database: unsupported jsonb version number 123
. I'm not sure if that's related to storing anOption<MyEnum>
instead of aMyEnum
. I also don't know if there's an easier way to handle this.Beta Was this translation helpful? Give feedback.
All reactions