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
Better support for type conversions #10
Comments
I'm interested in adding UUID to the list of supported types, pulling in the UUID type from the uuid package on hackage. I'm going to try to fork and add it, but I'm still a bit of a newb with Haskell, so not sure how well that's going to go. Before I spend a bunch of time trying to work out the details of that do you have any objection to pulling in a dependency on uuid? |
The work to add support for UUID is mostly done, I just need to add some tests around the new code and then I'll be ready to issue a pull request. |
Sorry for not responding a little sooner. This is actually a surprisingly common question. The answer is that you don't need to modify postgresql-simple at all, all you have to do is add a FromField instance for the Haskell type you want to represent UUIDs. I've been meaning to add this exact case as sample code in FromField, actually. Also, you might be interested in looking at the improved FromField documentation in the 0.3 branch. Here's something that should be pretty close to being correct:
Since postgresql's UUID type has a stable oid, we can look at that. For types provided by extensions, such as hstore, you should use the |
Also, I will say that I have considered adding out-of-box support for UUIDs, but after consulting some of the postgresql-simple users that use UUIDs we decided to keep postgresql-simple more minimal, with fewer dependencies on this count for the time being. |
Wouldn't you also need to create a ToField instance for the UUID type? The work I've done so far was to create a FromField and ToField instance and it seems to work, although I suppose I can see not wanting to pull in the extra dependency just to support UUID. I suppose I could always make the instances a standalone module, something like postgresql-simple-uuid. |
Depends on your needs, but for whatever reason ToField instances for UUID aren't asked about as often. We should offer both for out-of-box UUID support, though. |
Well, there's more work to be done, on this issue, but there's always more work to be done on this issue. I haven't added out-of-box support for network addresses (yet?), and decided against out-of-box support for UUIDs for the time being although I may change my mind, and have included a UUID FromField instance as an explicit example in the documentation. However recent versions do support arrays and hstores, and I have rewritten the time parsers. So given that this is a fairly generic and on-going issue, I'm going to close it. If anybody wants to request support for another specific type, feel free to open another issue. |
See, for example, #4; we should add support for network addresses and universally unique identifiers among others.
Also, Haskell's UTCTime doesn't support
infinity
or-infinity
, whereas PostgreSQL's timestamp type does.The text was updated successfully, but these errors were encountered: