Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default impl for insert_ that does not do a secondary query #1449

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for persistent

## 2.14.4.1

* [#1449](https://github.com/yesodweb/persistent/pull/1449)
* Default implementation for `insert_` which doesn't perform any unnecessary
queries.

## 2.14.4.0

* [#1440](https://github.com/yesodweb/persistent/pull/1440)
Expand Down
12 changes: 12 additions & 0 deletions persistent/Database/Persist/Sql/Orphan/PersistStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ instance PersistStoreWrite SqlBackend where
rawExecute sql $
map updatePersistValue upds `mappend` keyToValues k

insert_ val = do
conn <- ask
let vals = mkInsertValues val
case connInsertSql conn (entityDef (Just val)) vals of
ISRSingle sql -> do
withRawQuery sql vals $ do
pure ()
ISRInsertGet sql1 _sql2 -> do
rawExecute sql1 vals
ISRManyKeys sql _fs -> do
rawExecute sql vals

insert val = do
conn <- ask
let esql = connInsertSql conn t vals
Expand Down
2 changes: 1 addition & 1 deletion persistent/persistent.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent
version: 2.14.4.0
version: 2.14.4.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down