Skip to content

Commit da29c72

Browse files
Merge pull request #44 from brandonchinn178/fixes
Updates + fixes to README examples
2 parents 64a0404 + 29ca469 commit da29c72

12 files changed

+68
-20
lines changed

.circleci/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ workflows:
236236
- run_build_and_test:
237237
name: test_latest
238238
latest: true
239+
- run_build_and_test:
240+
name: test_ghc_9.0
241+
stack_yaml: stack-ghc-9.0.yaml
239242
- run_build_and_test:
240243
name: test_ghc_8.10
241244
stack_yaml: stack-ghc-8.10.yaml

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Unreleased
22

3+
# 0.4.0.0
4+
5+
* Add some mtl instances: `MonadThrow`, `MonadCatch`, `MonadMask`, `MonadLogger`, `MonadReader`
6+
* Removed support for GHC 8.2, 8.4
7+
* Add `MonadSqlQuery (TransactionM m)` superclass constraint to allow writing functions generic on some `MonadSqlQuery m` using `withTransaction`, as shown in examples in README
8+
39
# 0.3.0.0
410

511
* Add `unsafeLiftSql` ([#38](https://github.com/brandonchinn178/persistent-mtl/pull/38))

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ import Database.PostgreSQL.Simple.Errors (isSerializationError)
239239
main :: IO ()
240240
main = withPostgresqlPool "..." 5 $ \pool -> do
241241
let env = mkSqlQueryEnv pool $ \env -> env
242-
{ retryIf = isSerializationError . fromException
242+
{ retryIf = maybe False isSerializationError . fromException
243243
, retryLimit = 100 -- defaults to 10
244244
}
245245

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: persistent-mtl
2-
version: 0.3.0.0
2+
version: 0.4.0.0
33
maintainer: Brandon Chinn <[email protected]>
44
synopsis: Monad transformer for the persistent API
55
description: |

persistent-mtl.cabal

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: persistent-mtl
8-
version: 0.3.0.0
8+
version: 0.4.0.0
99
synopsis: Monad transformer for the persistent API
1010
description: A monad transformer and mtl-style type class for using the
1111
persistent API directly in your monad transformer stack.
@@ -64,6 +64,7 @@ test-suite persistent-mtl-test
6464
type: exitcode-stdio-1.0
6565
main-is: Main.hs
6666
other-modules:
67+
Basic
6768
Example
6869
Generated
6970
Integration

src/Database/Persist/Monad/Class.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ in order to interpret how to run a
66
'Database.Persist.Monad.SqlQueryRep.SqlQueryRep' sent by a lifted function from
77
@Database.Persist.Monad.Shim@.
88
-}
9+
{-# LANGUAGE FlexibleContexts #-}
910
{-# LANGUAGE TypeFamilies #-}
11+
{-# LANGUAGE UndecidableSuperClasses #-}
1012

1113
module Database.Persist.Monad.Class
1214
( MonadSqlQuery(..)
@@ -29,7 +31,7 @@ import Data.Typeable (Typeable)
2931
import Database.Persist.Monad.SqlQueryRep (SqlQueryRep)
3032

3133
-- | The type-class for monads that can run persistent database queries.
32-
class Monad m => MonadSqlQuery m where
34+
class (Monad m, MonadSqlQuery (TransactionM m)) => MonadSqlQuery m where
3335
type TransactionM m :: Type -> Type
3436

3537
-- | Interpret the given SQL query operation.

stack-ghc-8.10.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
resolver: lts-18.4
1+
resolver: lts-18.18
22

33
extra-deps:
4-
- persistent-postgresql-2.13.0.2
5-
- explainable-predicates-0.1.2.0
4+
- explainable-predicates-0.1.2.0
65

76
flags:
87
explainable-predicates:

stack-ghc-9.0.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resolver: nightly-2021-12-16
2+
3+
extra-deps:
4+
- explainable-predicates-0.1.2.0
5+
6+
flags:
7+
explainable-predicates:
8+
regex: false
9+
10+
ghc-options:
11+
"$locals": -Werror

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
stack-ghc-8.8.yaml
1+
stack-ghc-8.10.yaml

stack.yaml.lock

+4-11
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ packages:
1111
sha256: b7423cfba1171b8c2a500e337b66eb40bbb5d4a6a99e6ce6463d637fe118ebe0
1212
original:
1313
hackage: explainable-predicates-0.1.2.0
14-
- completed:
15-
hackage: syb-0.7.2.1@sha256:bf42655a213402215299e435c52f799e76cbec0b984cd7153d6b9af8a1c0803f,3815
16-
pantry-tree:
17-
size: 3396
18-
sha256: 3ee55cc33d69da2953e7093f99199fbc0bfa9d90dccd19cac101d09befa5bbb3
19-
original:
20-
hackage: syb-0.7.2.1
2114
snapshots:
2215
- completed:
23-
size: 534126
24-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/31.yaml
25-
sha256: 637fb77049b25560622a224845b7acfe81a09fdb6a96a3c75997a10b651667f6
26-
original: lts-16.31
16+
size: 586296
17+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/18.yaml
18+
sha256: 63539429076b7ebbab6daa7656cfb079393bf644971156dc349d7c0453694ac2
19+
original: lts-18.18

test/Basic.hs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{-# LANGUAGE GADTs #-}
2+
{-# LANGUAGE LambdaCase #-}
3+
{-# LANGUAGE TypeApplications #-}
4+
5+
module Basic where
6+
7+
import Test.Tasty
8+
import Test.Tasty.HUnit
9+
10+
import Database.Persist.Monad
11+
import Database.Persist.Monad.TestUtils
12+
import Example
13+
14+
tests :: TestTree
15+
tests = testGroup "Basic functionality tests"
16+
[ testCase "Ensure withTransaction README example typechecks" $ do
17+
let foo :: MonadSqlQuery m => m ()
18+
foo = insert_ $ person "Alice"
19+
bar :: MonadSqlQuery m => m ()
20+
bar = insert_ $ person "Bob"
21+
fooAndBar :: MonadSqlQuery m => m ()
22+
fooAndBar = withTransaction $ foo >> bar
23+
runMockSqlQueryT fooAndBar
24+
[ withRecord @Person $ \case
25+
Insert_ _ -> Just ()
26+
_ -> Nothing
27+
, withRecord @Person $ \case
28+
Insert_ _ -> Just ()
29+
_ -> Nothing
30+
]
31+
]

test/Main.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Test.Tasty
22

3+
import qualified Basic
34
import qualified Integration
45
import qualified MockSqlQueryT
56
import qualified Mocked
@@ -10,7 +11,8 @@ main = defaultMain tests
1011

1112
tests :: TestTree
1213
tests = testGroup "persistent-mtl"
13-
[ Mocked.tests
14+
[ Basic.tests
15+
, Mocked.tests
1416
, Integration.tests
1517
, MockSqlQueryT.tests
1618
, SqlQueryRepTest.tests

0 commit comments

Comments
 (0)