Skip to content

Commit 23e97a9

Browse files
committed
Merge pull request #10 from helium/documentation
Spruce up the documentation.
2 parents 7b2fb40 + 902f6cc commit 23e97a9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

postgresql-transactional.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: postgresql-transactional
2-
version: 1.1.0
2+
version: 1.1.1
33
synopsis: a transactional monad on top of postgresql-simple
44
license: MIT
55
license-file: LICENSE

src/Database/PostgreSQL/Transaction.hs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,26 @@
44
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
55
{-# LANGUAGE MultiParamTypeClasses #-}
66

7+
{-|
8+
Module : Database.PostgreSQL.Transaction
9+
Copyright : (c) Helium Systems, Inc.
10+
License : MIT
11+
Maintainer : [email protected]
12+
Stability : experimental
13+
Portability : GHC
14+
15+
This module provdes querying with and executing SQL statements that replace
16+
the ones found in @Database.PostgreSQL.Simple@.
17+
18+
Please note that the parameter order is reversed when compared to the functions
19+
provided by postgresql-simple. This is a conscious choice made so as to ease
20+
use of a SQL quasiquoter.
21+
22+
-}
23+
724
module Database.PostgreSQL.Transaction
8-
( PGTransaction
9-
, PGTransactionT
25+
( PGTransactionT
26+
, PGTransaction
1027
, runPGTransactionT
1128
, runPGTransactionT'
1229
, runPGTransactionIO
@@ -34,6 +51,8 @@ import Database.PostgreSQL.Simple.ToRow
3451
import qualified Database.PostgreSQL.Simple.Transaction as Postgres.Transaction
3552
import qualified Database.PostgreSQL.Simple.Types as PGTypes
3653

54+
-- | The Postgres transaction monad transformer. This is implemented as a monad transformer
55+
-- so as to integrate properly with monadic logging libraries like @monad-logger@ or @katip@.
3756
newtype PGTransactionT m a =
3857
PGTransactionT (ReaderT Postgres.Connection m a)
3958
deriving ( Functor
@@ -44,8 +63,11 @@ newtype PGTransactionT m a =
4463
, MonadIO
4564
)
4665

66+
-- | A type alias for occurrences of 'PGTransactionT' in the IO monad.
4767
type PGTransaction = PGTransactionT IO
4868

69+
-- | Runs a transaction in the base monad @m@ with a provided 'IsolationLevel'.
70+
-- An instance of MonadBaseControl is required so as to handle lifted calls to 'catch' correctly.
4971
runPGTransactionT' :: MonadBaseControl IO m
5072
=> Postgres.Transaction.IsolationLevel
5173
-> PGTransactionT m a
@@ -56,6 +78,7 @@ runPGTransactionT' isolation (PGTransactionT pgTrans) conn =
5678
Postgres.Transaction.withTransactionLevel isolation conn (run pgTrans)
5779
in control runTransaction `runReaderT` conn
5880

81+
-- | As 'runPGTransactionT'', but with the 'DefaultIsolationLevel' isolation level.
5982
runPGTransactionT :: MonadBaseControl IO m
6083
=> PGTransactionT m a
6184
-> Postgres.Connection
@@ -95,12 +118,15 @@ execute :: (ToRow input, MonadIO m)
95118
-> PGTransactionT m Int64
96119
execute params q = ask >>= (\conn -> liftIO $ Postgres.execute conn q params)
97120

121+
-- | As 'Database.PostgreSQL.Simple.executeMany', but operating in the transaction monad.
122+
-- If any one of these computations fails, the entire block will be rolled back.
98123
executeMany :: (ToRow input, MonadIO m)
99124
=> [input]
100125
-> Postgres.Query
101126
-> PGTransactionT m Int64
102127
executeMany params q = ask >>= (\conn -> liftIO $ Postgres.executeMany conn q params)
103128

129+
-- | Identical to 'Database.PostgreSQL.Simple.returning', save parameter order.
104130
returning :: (ToRow input, FromRow output, MonadIO m)
105131
=> [input]
106132
-> Postgres.Query
@@ -132,6 +158,7 @@ queryOnly :: (ToRow input, FromField f, MonadIO m)
132158
-> PGTransactionT m (Maybe f)
133159
queryOnly params q = fmap Postgres.fromOnly <$> queryHead params q
134160

161+
-- | As 'Database.PostgreSQL.Simple.formatQuery', save parameter order.
135162
formatQuery :: (ToRow input, MonadIO m)
136163
=> input
137164
-> Postgres.Query

0 commit comments

Comments
 (0)