yesodweb/persistent — Issue #39: Function insertUnique
Author: meteficha
Created: 2012-01-11 12:18:48+00:00
State: open

Hello!

I've been using this and would like to know if it would be useful enough to be included on `persistent`:

```haskell
-- | Like 'insert', but returns 'Nothing' when the record
-- couldn't be inserted because of a uniqueness constraint.
insertUnique :: (PersistBackend b m,
PersistEntity val,
MonadBaseControl IO (b m)) =>
val -> b m (Maybe (Key b val))
insertUnique datum = do
isUnique <- checkUnique datum
if isUnique then Just <$> insert datum else return Nothing
```