Copyright | © Clément Delafargue 2018 Théophile Choutri 2021 |
---|---|
License | MIT |
Maintainer | theophile@choutri.eu |
Stability | stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
The DBT
plumbing module to handle database queries and pools
Synopsis
- mkPool :: ConnectInfo -> Int -> NominalDiffTime -> Int -> IO (Pool Connection)
- withPool :: MonadIO m => Pool Connection -> DBT IO a -> m a
- execute :: (ToRow params, MonadIO m) => QueryNature -> Query -> params -> DBT m Int64
- executeMany :: (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)
- queryOne_ :: (FromRow result, MonadIO m) => QueryNature -> Query -> 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 :: MonadIO m => Pool Connection -> DBT IO 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
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
executeMany :: (ToRow params, MonadIO m) => QueryNature -> Query -> [params] -> DBT m Int64 Source #
Query wrapper for SQL statements that operate on multiple rows which do not return.
Since: 0.0.2.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
queryOne_ :: (FromRow result, MonadIO m) => QueryNature -> Query -> DBT m (Maybe result) Source #
Query wrapper that returns one result and does not take an argument
Since: 0.0.2.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
Show QueryNature Source # | |
Defined in Database.PostgreSQL.Entity.DBT showsPrec :: Int -> QueryNature -> ShowS # show :: QueryNature -> String # showList :: [QueryNature] -> ShowS # | |
Eq QueryNature Source # | |
Defined in Database.PostgreSQL.Entity.DBT (==) :: QueryNature -> QueryNature -> Bool # (/=) :: QueryNature -> QueryNature -> Bool # |