Skip to content

Commit

Permalink
checkpoint in liftSql (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored Dec 7, 2023
1 parent 168b032 commit 360bd4d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## [_Unreleased_](https://github.com/freckle/freckle-app/compare/v1.10.8.0...main)
## [_Unreleased_](https://github.com/freckle/freckle-app/compare/v1.11.0.0...main)

## [v1.11.0.0](https://github.com/freckle/freckle-app/compare/v1.10.8.0...v1.11.0.0)

- Add `MonadUnliftIO` superclass to `MonadSqlBackend`
- Use `checkpointCallStack` in `liftSql` to help grab more stack frames

## [v1.10.8.0](https://github.com/freckle/freckle-app/compare/v1.10.7.0...v1.10.8.0)

Expand Down
2 changes: 1 addition & 1 deletion freckle-app.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.18
-- see: https://github.com/sol/hpack

name: freckle-app
version: 1.10.8.0
version: 1.11.0.0
synopsis: Haskell application toolkit used at Freckle
description: Please see README.md
category: Utils
Expand Down
9 changes: 5 additions & 4 deletions library/Freckle/App/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.SqlQQ (sql)
import Freckle.App.Env (Timeout (..))
import qualified Freckle.App.Env as Env
import Freckle.App.Exception.MonadUnliftIO
import Freckle.App.OpenTelemetry
import Freckle.App.Stats (HasStatsClient)
import qualified Freckle.App.Stats as Stats
Expand All @@ -76,15 +77,15 @@ import Yesod.Core.Types (HandlerData (..), RunHandlerEnv (..))

-- | A monadic context in which a SQL backend is available
-- for running database queries
class MonadIO m => MonadSqlBackend m where
class MonadUnliftIO m => MonadSqlBackend m where
getSqlBackendM :: m SqlBackend

instance (HasSqlBackend r, MonadIO m) => MonadSqlBackend (ReaderT r m) where
instance (HasSqlBackend r, MonadUnliftIO m) => MonadSqlBackend (ReaderT r m) where
getSqlBackendM = asks getSqlBackend

-- | Generalize from 'SqlPersistT' to 'MonadSqlBackend'
liftSql :: MonadSqlBackend m => ReaderT SqlBackend m a -> m a
liftSql (ReaderT f) = getSqlBackendM >>= f
liftSql :: (MonadSqlBackend m, HasCallStack) => ReaderT SqlBackend m a -> m a
liftSql (ReaderT f) = checkpointCallStack $ getSqlBackendM >>= f

-- | The constraint @'MonadSqlTx' db m@ indicates that @m@ is a monadic
-- context that can run @db@ actions, usually as a SQL transaction.
Expand Down
2 changes: 1 addition & 1 deletion library/Freckle/App/Test/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bodyContains = liftYesodExample . Yesod.Test.bodyContains

-- | Clears the current cookies
testClearCookies :: forall m site. MonadYesodExample site m => m ()
testClearCookies = liftYesodExample $ Yesod.Test.testClearCookies
testClearCookies = liftYesodExample Yesod.Test.testClearCookies

-- | Deletes the cookie of the given name
testDeleteCookie
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: freckle-app
version: 1.10.8.0
version: 1.11.0.0
maintainer: Freckle Education
category: Utils
github: freckle/freckle-app
Expand Down

0 comments on commit 360bd4d

Please sign in to comment.