Support for composite types. #83
Replies: 7 comments 1 reply
-
|
I would love to see this! I am running in the same problem right now. |
Beta Was this translation helpful? Give feedback.
-
|
Hello! I'm not sure this can be done right now in Postgres, I'll need to have a look at how those types are represented internally by Postgres and if it stores enough informations we can access to generate proper types from it. If I recall correctly what blocked me was that Postgres used a generic "record" type or something like that for those custom types |
Beta Was this translation helpful? Give feedback.
-
|
Small update: looking into it, there might be a way to actually generate code for custom types! The only downside is that all fields of a custom type are always nullable so the generated code would look like this: pub type PreferredPositionType {
PreferredPositionType(position: Option(PlayerPosition), preference: Option(PreferenceType))
}It's not the best, but Postgres does not allow adding a not null constraint to the fields of custom types |
Beta Was this translation helpful? Give feedback.
-
|
That's pretty cool! 😍 |
Beta Was this translation helpful? Give feedback.
-
|
@ninanomenon (lmao your name still breaking github UI, love it) could you share a bit about your use case please 🙏 @AlexanderVanDamme In this case you may want to use a table for the preferred_positions rather than an array of rows inside a table. This is generally considered best practice with RDBMS, and here specifically it means that you won't have to deal with the |
Beta Was this translation helpful? Give feedback.
-
|
We are using enums a lot in different systems. For example to store the state of connected creditcard terminals. Just strings would work too but these states are pretty defined over the entire platform. (Braking UIs is my hobby ✨) |
Beta Was this translation helpful? Give feedback.
-
|
I'm making this a discussion so we can hear from more folks and learn about other use cases before rushing in an implementation! Thanks all! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
At first i had just a jsonb for these preferred positions, but since this was untyped i decided to create a composite type for them:
this player_position and preference type is both an enum
ALTER TABLE players ADD COLUMN preferred_positions preferred_position_type[] DEFAULT '{}';But when i run it i get the following error
gleam run -m squirrel
Compiled in 0.03s
Running squirrel.main
Error: Unsupported type
One of the rows returned by this query has type
preferred_position_typewhich I cannot currently generate codefor.
If you would like for this type to be supported, please open an
issue at
https://github.com/giacomocavalieri/squirrel/issues/new
🥜 I could still generate 4 queries.
Would be nice if such typing would be supported, would cleanup the decoders needed for it !
(or maybe there's other ways to type such data?)
Beta Was this translation helpful? Give feedback.
All reactions