Visitar URL original
`repsertMany` does not match `mapM_ (uncurry repsert)` · Issue #832 · yesodweb/persistent · GitHub
Skip to content

repsertMany does not match mapM_ (uncurry repsert) #832

Closed

Description

@naushadh

Issue

repsert works like so:

  • Find record by ID
  • If found, replace record for ID
  • else, insert record with ID

repsertMany works like so:

  • Find records by Ids
  • new ids = given ids diff found ids
  • insert records matching new ids

The following step is missing in repsertMany to make it symmetric with mapM_ (uncurry repsert):

  • replace records matching found ids

Issue was introduced at the very conception of the feature, and there are no tests to verify this API.

Suggested fix

Since there is no batch means to add the missing step mentioned above, we should perhaps let each driver implement its own repsertMany natively akin to putMany; i.e., create a new field in SqlBackend called connRepsertManySql before letting each backend define it.

Bonus, this will actually address race condition errors/deadlocks arising from non-atomic client side operations (SELECT + INSERT) on the same table. I've run into parallel insert errors with repsertMany but never with the natively/atomically implemented putMany using Postgres 10.

Activity

  1. added a commit that references this issue on Oct 5, 2018
    04d1c51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions