Skip to content

Commit

Permalink
fixup! fix: Avoid unnecessary UPDATE on conflicted column when upserting
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Jul 10, 2024
1 parent c448afb commit ea9f72d
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/PostgREST/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ actionQuery (DbCrud plan@MutateReadPlan{mrMutation=MutationUpdate, ..}) conf api

actionQuery (DbCrud plan@MutateReadPlan{mrMutation=MutationSingleUpsert, ..}) conf apiReq _ _ = do
resultSet <- writeQuery mrReadPlan mrMutatePlan mrMedia mrHandler apiReq conf
failPut resultSet
optionalRollback conf apiReq
pure $ DbCrudResult plan resultSet

Expand Down Expand Up @@ -209,18 +208,6 @@ writeQuery readPlan mutatePlan mType mHandler ApiRequest{iPreferences=Preference
pkCols
(configDbPreparedStatements conf)

-- Makes sure the querystring pk matches the payload pk
-- e.g. PUT /items?id=eq.1 { "id" : 1, .. } is accepted,
-- PUT /items?id=eq.14 { "id" : 2, .. } is rejected.
-- If this condition is not satisfied then nothing is inserted,
-- check the WHERE for INSERT in QueryBuilder.hs to see how it's done
failPut :: ResultSet -> DbHandler ()
failPut RSPlan{} = pure ()
failPut RSStandard{rsQueryTotal=queryTotal} =
when (queryTotal /= 1) $ do
lift SQL.condemn
throwError $ Error.ApiRequestError ApiRequestTypes.PutMatchingPkError

resultSetWTotal :: AppConfig -> ApiRequest -> ResultSet -> SQL.Snippet -> DbHandler ResultSet
resultSetWTotal _ _ rs@RSPlan{} _ = return rs
resultSetWTotal AppConfig{..} ApiRequest{iPreferences=Preferences{..}} rs@RSStandard{rsTableTotal=tableTotal} countQuery =
Expand Down

0 comments on commit ea9f72d

Please sign in to comment.