-
Notifications
You must be signed in to change notification settings - Fork 71
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
Comments
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. |
Hmm, there's more than one UUID package, and I'm not sure if there's a good package for representing CIDR. |
Honestly, probably the way to get started is simply to write newtype Cidr = Cidr ByteString toCidr :: Bytestring -> Maybe Cidr (Or Either ErrorMessage ByteString?) or some such; there are probably better names. That should be |
I ended up going with http://hackage.haskell.org/package/network-address, and I'm happy with it. |
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. |
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 asString
,ByteString
, orText
.Or, if you export the
compat
,mkCompats
, anddoConvert
functions (and make them more user friendly), it would be a lot easier to define one's own instance ofResult
for types like cidr and uuid.The text was updated successfully, but these errors were encountered: