yesodweb/persistent — pull request #160 by bergmark (2013-09-19 14:34:56+00:00)
Title: persistent-postgresql: Newtype conversions in PersistDbSpecific

As discussed in #153, this adds a newtype around `PersistDbSpecific` conversions that doesn't do validation. This way native postgresql types that persistent doesn't handle by default can be converted to ByteString.

Example for UUID:

```
{-# LANGUAGE OverloadedStrings #-}
module UUID where

import Database.Persist
import Database.Persist.Sql
import qualified Data.ByteString.Char8 as B
import qualified Data.UUID as UUID

instance PersistField UUID.UUID where
toPersistValue u = PersistDbSpecific . B.pack . UUID.toString $ u

fromPersistValue (PersistDbSpecific t) = case UUID.fromString $ B.unpack t of
Just x -> Right x
Nothing -> Left "Invalid UUID"
fromPersistValue _ = Left "Not PersistDBSpecific"

instance PersistFieldSql UUID.UUID where
sqlType _ = SqlOther "UUID"

```