yesodweb / yesodweb/persistent
add repsertBy functionality
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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