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

other postgres string types #4

Closed
pheaver opened this issue Jan 8, 2012 · 5 comments
Closed

other postgres string types #4

pheaver opened this issue Jan 8, 2012 · 5 comments

Comments

@pheaver
Copy link

pheaver commented Jan 8, 2012

There are many postgres string types (I'm dealing with the cidr and uuid types right now) with no Result instance in postgresql-simple, and defining one is tedious.

One solution is to extend okText to include them, so that the user can just read them as String, ByteString, or Text.

Or, if you export the compat, mkCompats, and doConvert functions (and make them more user friendly), it would be a lot easier to define one's own instance of Result for types like cidr and uuid.

@lpsmith
Copy link
Owner

lpsmith commented Jan 8, 2012

It is unfortunate that you can't extend the set of PostgreSQL types that a Haskell type can be converted from in client code. I thought about this problem a little bit, but I don't know of an easy solution. There might be one involving some advanced type-level hackery.

CIDR and UUID aren't really "string types" though; it's just that PostgreSQL treats a lot of the extended types as strings for the purposes of getting them into and out of the database.

I'm thinking that it would be a lot more appropriate to define new Haskell datatypes for representing CIDRs and UUIDs. I would be very interested in moving these types into postgresql-simple, or perhaps the types should be in separate packages and Result instances should be provided by postgresql-simple.

I definitely do not want to export the functions you mention; they were refactored a bit from mysql-simple and should probably be refactored a bit further. If you want to use them, I would recommend that you copy and paste them into your code.

@pheaver
Copy link
Author

pheaver commented Jan 8, 2012

Hmm, there's more than one UUID package, and I'm not sure if there's a good package for representing CIDR.

@lpsmith
Copy link
Owner

lpsmith commented Jan 9, 2012

Honestly, probably the way to get started is simply to write

newtype Cidr = Cidr ByteString

toCidr :: Bytestring -> Maybe Cidr (Or Either ErrorMessage ByteString?)
fromCidr :: Cidr -> ByteString

or some such; there are probably better names. That should be
enough to get you started, and then you could elaborate the type (and
operations on the type) as needed.

@pheaver
Copy link
Author

pheaver commented Jan 9, 2012

I ended up going with http://hackage.haskell.org/package/network-address, and I'm happy with it.

@lpsmith
Copy link
Owner

lpsmith commented Jan 10, 2012

Glancing at that package, it looks like a reasonable start. There are a few things I don't like about it, especially it's abuse of the "Read" type class. (Which, in all honesty, probably isn't as bad as the nearly ubiquitous abuse of the "Show" typeclass)

Like I said, I am very much interested in supporting these types out-of-box, so if you find/write a particularly nice UUID or network address library (maybe by using network-address as a starting point), then I'd love to add Result instances for them to postgresql-simple.

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

No branches or pull requests

2 participants