Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions persistent-postgresql/Database/Persist/Postgresql.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ excludeNotEqualToOriginal field =
-- Called thusly, this method will insert a new record (if none exists) OR update a recordField with a new value
-- assuming the condition in the last block is met.
--
-- -- @since 2.12.1.0
-- @since 2.12.1.0
upsertManyWhere ::
forall record backend m.
( backend ~ PersistEntityBackend record,
Expand All @@ -1874,14 +1874,10 @@ upsertManyWhere ::
PersistEntity record,
MonadIO m
) =>
-- | A list of the records you want to insert, or update
[record] ->
-- | A list of the fields you want to copy over.
[HandleUpdateCollision record] ->
-- | A list of the updates to apply that aren't dependent on the record being inserted.
[Update record] ->
-- | A filter condition that dictates the scope of the updates
[Filter record] ->
[record] -> -- ^ A list of the records you want to insert, or update
[HandleUpdateCollision record] -> -- ^ A list of the fields you want to copy over.
[Update record] -> -- ^ A list of the updates to apply that aren't dependent on the record being inserted.
[Filter record] -> -- ^ A filter condition that dictates the scope of the updates
ReaderT backend m ()
upsertManyWhere [] _ _ _ = return ()
upsertManyWhere records fieldValues updates filters = do
Expand Down
9 changes: 8 additions & 1 deletion persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Changelog for persistent

## 2.12.1.1

* [#1229](https://github.com/yesodweb/persistent/pull/1229)
* The `#id` labels are now generated for entities.

## 2.12.1.0

* [#1226](https://github.com/yesodweb/persistent/pull/1226)
* [#1218](https://github.com/yesodweb/persistent/pull/1218)
* Refactoring name generating functions in TH
* [#1226](https://github.com/yesodweb/persistent/pull/1226)
* Expose the `filterClause` and `filterClauseWithValues` functions to support
the `upsertWhere` functionality in `persistent-postgresql`.

Expand Down
59 changes: 31 additions & 28 deletions persistent/Database/Persist/Class/PersistUnique.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
{-# LANGUAGE TypeOperators #-}

module Database.Persist.Class.PersistUnique
( PersistUniqueRead(..)
, PersistUniqueWrite(..)
, OnlyOneUniqueKey(..)
, onlyOneUniqueDef
, AtLeastOneUniqueKey(..)
, atLeastOneUniqueDef
, NoUniqueKeysError
, MultipleUniqueKeysError
, getByValue
, getByValueUniques
, insertBy
, insertUniqueEntity
, replaceUnique
, checkUnique
, checkUniqueUpdateable
, onlyUnique
, defaultUpsertBy
, defaultPutMany
, persistUniqueKeyValues
)
where
( PersistUniqueRead(..)
, PersistUniqueWrite(..)
, OnlyOneUniqueKey(..)
, onlyOneUniqueDef
, AtLeastOneUniqueKey(..)
, atLeastOneUniqueDef
, NoUniqueKeysError
, MultipleUniqueKeysError
, getByValue
, getByValueUniques
, insertBy
, insertUniqueEntity
, replaceUnique
, checkUnique
, checkUniqueUpdateable
, onlyUnique
, defaultUpsertBy
, defaultPutMany
, persistUniqueKeyValues
)
where

import Control.Monad (liftM)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Trans.Reader (ReaderT)
import Data.Function (on)
import Data.List ((\\), deleteFirstsBy)
import Data.List (deleteFirstsBy, (\\))
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NEL
import qualified Data.Map as Map
import Data.Maybe (catMaybes)
import GHC.TypeLits (ErrorMessage(..))

import Database.Persist.Types
import Database.Persist.Class.PersistStore
import Database.Persist.Class.PersistEntity
import Database.Persist.Class.PersistStore
import Database.Persist.Types

-- | Queries against 'Unique' keys (other than the id 'Key').
--
Expand Down Expand Up @@ -419,10 +419,13 @@ insertBy val = do
-- > +----+-------+-----+

insertUniqueEntity
:: forall record backend m. (MonadIO m
,PersistRecordBackend record backend
,PersistUniqueWrite backend)
=> record -> ReaderT backend m (Maybe (Entity record))
:: forall record backend m
. ( MonadIO m
, PersistRecordBackend record backend
, PersistUniqueWrite backend
)
=> record
-> ReaderT backend m (Maybe (Entity record))
insertUniqueEntity datum =
fmap (\key -> Entity key datum) `liftM` insertUnique datum

Expand Down
Loading