Skip to content

Commit 0624c8f

Browse files
committed
Add _onConflictDoNothing
1 parent b6aabfb commit 0624c8f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for Entity
22

3+
## 0.0.7.0 -- XXXX-XX-XX
4+
5+
* Add `_onConflictDoNothing`
6+
37
## 0.0.6.0 -- 2025-05-20
48

59
* The `prod` flag is removed, end of the experiment. End-users should be in charge of logging the queries.

src/Database/PostgreSQL/Entity.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Database.PostgreSQL.Entity
3838
, insert
3939
, insertMany
4040
, upsert
41+
, upsertOnPK_
4142

4243
-- ** Update
4344
, update
@@ -280,7 +281,7 @@ insert
280281
-> DBT m ()
281282
insert fs = void $ execute (_insert @e) fs
282283

283-
{-| Insert an entity with a "ON CONFLICT DO UPDATE" clause on the primary key as the conflict target
284+
{-| Insert an entity with an "ON CONFLICT DO UPDATE" clause on the primary key as the conflict target
284285
285286
@since 0.0.2.0
286287
-}
@@ -296,6 +297,20 @@ upsert entity fieldsToReplace = void $ execute (_insert @e <> _onConflictDoUpdat
296297
where
297298
conflictTarget = V.singleton $ primaryKey @e
298299

300+
{-| Insert an entity with an "ON CONFLICT DO NOTHING" clause
301+
302+
@since 0.0.2.0
303+
-}
304+
upsertOnPK_
305+
:: forall e values m
306+
. (Entity e, ToRow values, MonadIO m)
307+
=> values
308+
-- ^ Entity to insert
309+
-> DBT m ()
310+
upsertOnPK_ entity = void $ execute (_insert @e <> _onConflictDoNothing conflictTarget ) entity
311+
where
312+
conflictTarget = V.singleton $ primaryKey @e
313+
299314
{-| Insert multiple rows of an entity.
300315
301316
@since 0.0.2.0

0 commit comments

Comments
 (0)