Copyright | © Clément Delafargue 2018 Théophile Choutri 2021 |
---|---|
License | MIT |
Maintainer | theophile@choutri.eu |
Stability | stable |
Safe Haskell | None |
Language | Haskell2010 |
The DBT
plumbing module to handle database queries and pools
Synopsis
- mkPool :: ConnectInfo -> Int -> NominalDiffTime -> Int -> IO (Pool Connection)
- withPool :: MonadBaseControl IO m => Pool Connection -> DBT m a -> m a
- withPool' :: forall errorType result m. (Exception errorType, MonadCatch m, MonadBaseControl IO m) => Pool Connection -> DBT m result -> m (Either errorType result)
- execute :: (ToRow params, MonadIO m) => QueryNature -> Query -> params -> DBT m Int64
- query :: (ToRow params, FromRow result, MonadIO m) => QueryNature -> Query -> params -> DBT m (Vector result)
- query_ :: (FromRow result, MonadIO m) => QueryNature -> Query -> DBT m (Vector result)
- queryOne :: (ToRow params, FromRow result, MonadIO m) => QueryNature -> Query -> params -> DBT m (Maybe result)
- data QueryNature
Documentation
mkPool :: ConnectInfo -> Int -> NominalDiffTime -> Int -> IO (Pool Connection) Source #
Create a Pool Connection with the appropriate parameters
Since: 0.0.1.0
withPool :: MonadBaseControl IO m => Pool Connection -> DBT m a -> m a Source #
Run a DBT action with no explicit error handling.
This functions is suited for using MonadError
error handling.
Example
let e1 = E 1 True True result <- runExceptT @EntityError $ do withPool pool $ insertEntity e1 withPool pool $ markForProcessing 1 case result of Left err -> print err Right _ -> putStrLn "Everything went well"
See the code in the example/
directory on GitHub
Since: 0.0.1.0
withPool' :: forall errorType result m. (Exception errorType, MonadCatch m, MonadBaseControl IO m) => Pool Connection -> DBT m result -> m (Either errorType result) Source #
Run a DBT action while handling errors as Exceptions.
This function wraps the DBT actions in a try
, so that exceptions
raised will be converted to the Left branch of the Either.
Since: 0.0.1.0
execute :: (ToRow params, MonadIO m) => QueryNature -> Query -> params -> DBT m Int64 Source #
Query wrapper for SQL statements which do not return.
Since: 0.0.1.0
query :: (ToRow params, FromRow result, MonadIO m) => QueryNature -> Query -> params -> DBT m (Vector result) Source #
Query wrapper that returns a Vector
of results
Since: 0.0.1.0
query_ :: (FromRow result, MonadIO m) => QueryNature -> Query -> DBT m (Vector result) Source #
Query wrapper that returns a Vector
of results and does not take an argument
Since: 0.0.1.0
queryOne :: (ToRow params, FromRow result, MonadIO m) => QueryNature -> Query -> params -> DBT m (Maybe result) Source #
Query wrapper that returns one result.
Since: 0.0.1.0
data QueryNature Source #
This sum type is given to the query
, queryOne
and execute
functions to help
with logging.
Since: 0.0.1.0
Instances
Eq QueryNature Source # | |
Defined in Database.PostgreSQL.Entity.DBT (==) :: QueryNature -> QueryNature -> Bool # (/=) :: QueryNature -> QueryNature -> Bool # | |
Show QueryNature Source # | |
Defined in Database.PostgreSQL.Entity.DBT showsPrec :: Int -> QueryNature -> ShowS # show :: QueryNature -> String # showList :: [QueryNature] -> ShowS # |