diff --git a/src/Database/PostgreSQL/Entity.hs b/src/Database/PostgreSQL/Entity.hs index 51d8d78..e7372d5 100644 --- a/src/Database/PostgreSQL/Entity.hs +++ b/src/Database/PostgreSQL/Entity.hs @@ -38,6 +38,7 @@ module Database.PostgreSQL.Entity , insert , insertMany , upsert + , upsertMany -- ** Update , update @@ -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