Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on db types to haskell types convertion #203

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

matsumonkie
Copy link

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 ?

@saurabhnanda
Copy link
Contributor

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)?

@saurabhnanda
Copy link
Contributor

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?

@saurabhnanda
Copy link
Contributor

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.

@matsumonkie
Copy link
Author

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 :-)

@tomjaguarpaw
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants