yesodweb/persistent — pull request #265 by danclien (2014-08-08 18:59:29+00:00)
Title: Adds support for PostgreSQL's enumerated types. Issue #246

This was my attempt at fixing Issue #246. I doubt it's as clean as it should be, but let me know if you have any suggestions.

## persistent-template

### Changes

* Generalized `derivePersistField` into `derivePersistFieldGeneric` that accepts a `Q Exp` for the `PersistFieldSql` instance.
* Added `derivePersistFieldSqlTypeOther` which creates the `PersistFieldSql` instance with `SqlOther`.
* This fixes migrations always using `VARCHAR` in #246.

### Example

#### PostgreSQL
```
CREATE TYPE color AS ENUM ('Red', 'Blue', 'Yellow');
```

##### Sum type
```
data Color = Red | Yellow | Blue deriving (Show, Read, Eq)
derivePersistFieldSqlTypeOther "Color" "color"
-- ^ ^
-- | +--- Name of type in PostgreSQL
-- +----------- Name of type in Haskell
```

#### Table definition
```
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person sql=people
name String
favorite_color Color default="'Blue'::color"
deriving Show
|]
```

## persistent-postgresql

### Changes

* Adds a check into `getGetter` that sees if the incoming type in a PostgreSQL Enum.
* If it is an Enum, it converts the `ByteString` to a `PersistText` via UTF8.
* This fixes reading the Enum in #246.