From 98ad8f8b64c086f3c69ad2e6e137e9286f962a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Choutri=20de=20Tarl=C3=A9?= Date: Sat, 21 Jun 2025 14:00:34 +0200 Subject: [PATCH] Add upsertMany --- src/Database/PostgreSQL/Entity.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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