yesodweb / yesodweb/persistent

Savepoint support

Open
#761 3 comments 0 reactions 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

postgresql-simple has it, an example manually combining it with Persistent can be found here: https://www.shimweasel.com/haskell/2016/07/21/yolo-oriented-database-programming

data Result
  = NotPresent
  | AlreadyAdded
  | NowAdded
  deriving (Eq,Show)

doAThing :: UUID -> UUID -> DB Result
doAThing barU fooU =
  handle uniqViolation $ do
    startTransaction
    inserted <-  insertSelectCount $
       from $
       \(foos,bars) ->
         do where_ (foos ^. FooUuid ==. val fooU)
            where_ (bars ^. BarUuid ==. val barU)
            return $ Baz <# (foos ^. FooId) <&> (bars ^. BarId)
    commitTransaction
    case inserted of
      0 -> return NotPresent
      1 -> return NowAdded
      n -> throwM (InvalidInsertedCount n)
  where
    uniqViolation
      :: SqlError -> DB Result
    uniqViolation _e = do
      rollbackTransaction
      return AlreadyAdded

    rollbackTransaction, startTransaction, commitTransaction :: DB ()
    startTransaction    = rawExecute "SAVEPOINT             savepointname" []
    commitTransaction   = rawExecute "RELEASE SAVEPOINT     savepointname" []
    rollbackTransaction = rawExecute "ROLLBACK TO SAVEPOINT savepointname" []

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

No repository files or tests are named. Start by reviewing Persistent's transaction APIs and the linked PostgreSQL example, then determine how savepoints should be exposed and supported across storage methods. Done means Persistent provides documented savepoint support with coverage for the relevant PostgreSQL behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, postgresql
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.