yesodweb / yesodweb/persistent

add repsertBy functionality

Open
#1,057 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

With the advent of AtLeastOneUniqueKey and newer methods that rely on it, there is one function missing from the suite: repsertBy.

I propose adding this method and making it analogous to the already existing insertBy:

repsertBy 
    ::
    ( MonadIO m
    , PersistUniqueWrite backend
    , PersistRecordBackend record backend 
    , AtLeastOneUniqueKey record
    )
    => record -> ReaderT backend m ()
repsertBy val = do 
    res <- getByValue val 
    case res of 
        Nothing -> insert_ val 
        Just (Entity key _) -> replace key val 

Happy to submit a PR to this effect!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing insertBy entry point in Database.Persist.Class and review the AtLeastOneUniqueKey-based methods. Check how getByValue, insert_, and replace are used, then add matching coverage in the existing test suite. Done means repsertBy handles both absent and present unique-key results with the proposed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.