haskell-beam / haskell-beam/beam
Compatibility with Postgres enumerations
- Dominant language
- Haskell
- Stars
- 635
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
First of all, thanks for the great library! It has been a breeze so far, and I really enjoyed writing DB access layer with it — something that's not happening too often!
Right now I'm stuck trying to do something, though. I've created a custom Postgres enumeration type (as in `CREATE TYPE post_type AS ENUM ('post', 'article', 'news');`) and I'm trying to make my Haskell type (a very similar `data PostType = TyPost | TyArticle | TyNews`) compatible with it. So I have
```haskell
instance (BeamBackend be, FromBackendRow be String) => FromBackendRow be PostType where
fromBackendRow = do
val <- fromBackendRow
case lookup val tys of
Just ty -> pure ty
_ -> fail $ "invalid value for PostType: " <> val
where tys = [ (postTypeName ty, ty) | ty <- [minBound .. maxBound] ]
```
but when I actually try to read something from the DB, I'm getting `BeamRowReadError {brreColumn = Just 13, brreError = ColumnTypeMismatch {ctmHaskellType = "Text", ctmSQLType = "post_type", ctmMessage = "types incompatible"}}`. I believe this is due to my implementation relying on `fromBackendRow` for strings and thus the `Typeable` magic derives that the column must have a textual type. Is there a good way for me to support Postgres-defined enum types?
I've read through https://github.com/tathougies/beam/blob/master/beam-postgres/examples/Pagila/Schema/CustomMigrateExample.hs , but it seems like it assumes the underlying representation is a textual one, so it does not apply directly.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.