| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.PostgreSQL.Tx.Internal
Contents
Synopsis
- data TxErrorType
- data TxException = TxException {}
- type family TxEnvs (xs :: [*]) r :: Constraint where ...
- class TxEnv a r where
- lookupTxEnv :: r -> a
- newtype TxM r a = UnsafeTxM {
- unsafeUnTxM :: ReaderT r IO a
- unsafeRunIOInTxM :: IO a -> TxM r a
- unsafeMkTxM :: (r -> IO a) -> TxM r a
- unsafeMksTxM :: TxEnv a r => (a -> IO b) -> TxM r b
- unsafeRunTxM :: r -> TxM r a -> IO a
- unsafeWithRunInIOTxM :: ((forall a. TxM r a -> IO a) -> IO b) -> TxM r b
- askTxEnv :: TxEnv a r => TxM r a
- unsafeLookupTxEnvIO :: TxEnv a r => r -> IO a
- throwExceptionTx :: Exception e => e -> TxM r a
- mapExceptionTx :: (Exception e, Exception e') => (e -> Maybe e') -> TxM r a -> TxM r a
- shouldRetryTx :: TxException -> Bool
- fromSqlState :: Maybe String -> TxErrorType
- unsafeMkTxException :: Exception e => (e -> Maybe String) -> e -> TxException
- unsafeMkTxException' :: Exception e => (e -> TxErrorType) -> e -> TxException
Disclaimer
Changes to this module will not be reflected in the library's version updates.
Internals
data TxErrorType Source #
Constructors
| TxSerializationFailure | |
| TxDeadlockDetected | |
| TxOtherError (Maybe String) | PostgreSQL |
Instances
| Eq TxErrorType Source # | |
Defined in Database.PostgreSQL.Tx.Internal | |
| Show TxErrorType Source # | |
Defined in Database.PostgreSQL.Tx.Internal Methods showsPrec :: Int -> TxErrorType -> ShowS # show :: TxErrorType -> String # showList :: [TxErrorType] -> ShowS # | |
data TxException Source #
Constructors
| TxException | |
Fields | |
Instances
| Show TxException Source # | |
Defined in Database.PostgreSQL.Tx.Internal Methods showsPrec :: Int -> TxException -> ShowS # show :: TxException -> String # showList :: [TxException] -> ShowS # | |
| Exception TxException Source # | |
Defined in Database.PostgreSQL.Tx.Internal Methods toException :: TxException -> SomeException # fromException :: SomeException -> Maybe TxException # displayException :: TxException -> String # | |
type family TxEnvs (xs :: [*]) r :: Constraint where ... Source #
Type family which allows for specifying several TxEnv constraints as
a type-level list.
Since: 0.2.0.0
class TxEnv a r where Source #
A type class for specifying how to acquire an environment value
to be used for running an implementation of a database library.
For example, your database library will likely require some sort of
connection value to discharge its effects; in this case, you'd want to
define an instance of TxEnv MyDBEnv Connection and use TxM MyDBEnv
as your monad for executing transactions.
Note that implementations should take care and ensure that multiple
instances are compatible with one another. For example, let's say you
have instances for both TxEnv E PgSimple.Connection and
TxEnv E LibPQ.Connection; if both of these implementations are grabbing
connections from a pool, you will end up with each of those database
libraries using different connections, and thus, would be running in
separate transactions!
Since: 0.2.0.0
Methods
lookupTxEnv :: r -> a Source #
Acquire a value a via the reader environment r which assists in
running a TxM in a transaction.
Since: 0.2.0.0
The transaction monad. Unifies all database integrations, regardless of
library, into a single monad. The r type parameter represents the reader
environment needed for applicable database libraries. For example,
postgresql-simple needs a Connection to run its functions, so
its interface will require that we can obtain a Connection from the r
using the TxEnv type class.
Since: 0.2.0.0
Constructors
| UnsafeTxM | |
Instances
| Monad (TxM r) Source # | |
| Functor (TxM r) Source # | |
| MonadFail (TxM r) Source # | |
Defined in Database.PostgreSQL.Tx.Internal | |
| Applicative (TxM r) Source # | |
| (TypeError ('Text "MonadIO is banned in TxM; use 'unsafeRunIOInTxM' if you are sure this is safe IO") :: Constraint) => MonadIO (TxM r) Source # | The Since: 0.1.0.0 |
Defined in Database.PostgreSQL.Tx.Internal | |
| Semigroup a => Semigroup (TxM r a) Source # | |
| Monoid a => Monoid (TxM r a) Source # | |
unsafeRunIOInTxM :: IO a -> TxM r a Source #
unsafeMkTxM :: (r -> IO a) -> TxM r a Source #
unsafeMksTxM :: TxEnv a r => (a -> IO b) -> TxM r b Source #
Similar to unsafeMkTxM but allows for constructing a TxM with a
reader function using a specific value from the environment.
Use this function with care - arbitrary IO should only be run
within a transaction when truly necessary.
Since: 0.2.0.0
unsafeRunTxM :: r -> TxM r a -> IO a Source #
unsafeLookupTxEnvIO :: TxEnv a r => r -> IO a Source #
Analogous to lookupTxEnv but can be run in IO instead of TxM.
Since: 0.2.0.0
throwExceptionTx :: Exception e => e -> TxM r a Source #
Throw an exception.
Since: 0.2.0.0
mapExceptionTx :: (Exception e, Exception e') => (e -> Maybe e') -> TxM r a -> TxM r a Source #
Catch an exception and map it to another exception type before rethrowing.
Since: 0.2.0.0
shouldRetryTx :: TxException -> Bool Source #
fromSqlState :: Maybe String -> TxErrorType Source #
unsafeMkTxException :: Exception e => (e -> Maybe String) -> e -> TxException Source #
unsafeMkTxException' :: Exception e => (e -> TxErrorType) -> e -> TxException Source #