haskell-opaleye
haskell-opaleye copied to clipboard
Documentation on db types to haskell types convertion
First thing first, thanks a lot for this awesome project ! I'm in the process the try to understand the source as I find it really interresting.
As a Haskell beginner, I sometime found a bit hard to use Opaleye. Issue #197 is something I have also ran into. I thought it could be nice to add some documentation on how to handle convertions.
What do you think ?
Why does one need to derive FromField AND QueryRunnerColumnDefault? Looking at the API surface, it seems that the latter has all the information required to teach Opaleye how to convert a PGText to Gender:
instance QueryRunnerColumnDefault PGText Gender where
Also, what about the other way round? How does Opaleye know how to convert a Gender to PGText (or whatever else raw SQL is going to accept)?
Also, I'm not clear how PGText came into the picture? In case of an ENUM datatype, wouldn't Postgres send it as a completely new type, altogether?
Also, a link to https://hackage.haskell.org/package/postgresql-simple-0.5.2.1/docs/Database-PostgreSQL-Simple-FromField.html in the documentation might be a good idea. It contains a more detailed example of how to handle parsing failures as well.
Also, I'm not clear how PGText came into the picture? In case of an ENUM datatype, wouldn't Postgres send it as a completely new type, altogether?
I think Postgres handle an enum type internally as an Int but present it as a string. Your enum type should probably as a PGString, not sure though.
Also, a link to https://hackage.haskell.org/package/postgresql-simple-0.5.2.1/docs/Database PostgreSQL-Simple-FromField.html in the documentation might be a good idea. It contains a more detailed example of how to handle parsing failures as well.
Yeah you're right, I have changed the PR. Thanks
Also, what about the other way round? How does Opaleye know how to convert a Gender to PGText (or whatever else raw SQL is going to accept)?
I don't know yet, still learning Opaleye :-)
Thanks very much for this. I don't really have time at the moment to handle all the inbound Opaleye requests I'm getting but I will get to this sooner or later!