Skip to content
Open
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
17 changes: 17 additions & 0 deletions src/Database/PostgreSQL/Entity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Database.PostgreSQL.Entity
, insert
, insertMany
, upsert
, upsertMany

-- ** Update
, update
Expand Down Expand Up @@ -295,6 +296,22 @@ upsert entity fieldsToReplace = void $ execute (_insert @e <> _onConflictDoUpdat
where
conflictTarget = V.singleton $ primaryKey @e

{-| Insert an entity with a "ON CONFLICT DO UPDATE" clause on the primary key as the conflict target

@since 0.0.2.0
-}
upsertMany
:: forall e values m
. (Entity e, ToRow values, MonadIO m)
=> [values]
-- ^ Entity to insert
-> Vector Field
-- ^ Fields to replace in case of conflict
-> DBT m ()
upsertMany entities fieldsToReplace = void $ executeMany (_insert @e <> _onConflictDoUpdate conflictTarget fieldsToReplace) entities
where
conflictTarget = V.singleton $ primaryKey @e

{-| Insert multiple rows of an entity.

@since 0.0.2.0
Expand Down