Skip to content

Commit

Permalink
make repsert a special case of repsertMany (#1452)
Browse files Browse the repository at this point in the history
* make repsert a special case of repsertMany

* bump changelog

* bump version

* actually bind arguments
  • Loading branch information
njohnwalker committed Dec 17, 2022
1 parent 946892b commit 0c57453
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions persistent/ChangeLog.md
@@ -1,5 +1,11 @@
# Changelog for persistent

## 2.14.4.3

* [#1452](https://github.com/yesodweb/persistent/pull/1452)
* Implement `repsert` as a special case of `respertMany`. Allows backend
specific behavior.

## 2.14.4.2

* [#1451](https://github.com/yesodweb/persistent/pull/1451)
Expand Down
14 changes: 8 additions & 6 deletions persistent/Database/Persist/Sql/Orphan/PersistStore.hs
Expand Up @@ -288,11 +288,7 @@ instance PersistStoreWrite SqlBackend where
where
go = insrepHelper "INSERT"

repsert key value = do
mExisting <- get key
case mExisting of
Nothing -> insertKey key value
Just _ -> replace key value
repsert key value = repsertMany [(key, value)]

repsertMany [] = return ()
repsertMany krsDups = do
Expand All @@ -307,7 +303,13 @@ instance PersistStoreWrite SqlBackend where
Just _ -> mkInsertValues r
case connRepsertManySql conn of
(Just mkSql) -> rawExecute (mkSql ent nr) (concatMap toVals krs)
Nothing -> mapM_ (uncurry repsert) krs
Nothing -> mapM_ repsert' krs
where
repsert' (key, value) = do
mExisting <- get key
case mExisting of
Nothing -> insertKey key value
Just _ -> replace key value

delete k = do
conn <- ask
Expand Down
2 changes: 1 addition & 1 deletion persistent/persistent.cabal
@@ -1,5 +1,5 @@
name: persistent
version: 2.14.4.2
version: 2.14.4.3
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down

0 comments on commit 0c57453

Please sign in to comment.