hyperion-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Hyperion.Database.HasDB

Synopsis

General comments

Hyperion.Database.HasDB provides typeclass HasDB which describes environments that contain a DatabaseConfig, which is extracted by Lens' dbConfigLens.

This is used in the following way: if we have a monad m that

  1. is an instance of MonadIO, i.e. embeds IO actions,
  2. an instance of MonadReader, i.e. it carries an environment,
  3. this environment is an instance of HasDB,

then we can create m-actions using withConnection, i.e.

doStuffWithConnection :: Sql.Connection -> IO a
...
do -- here we are in m monad
  ...
  result <- withConnection doStuffWithConnection
  ...

withConnection uses Data.Pool. See withResource for details.

Documentation

data DatabaseConfig Source #

Database information datatype

Constructors

DatabaseConfig 

Fields

Instances

Instances details
HasDB DatabaseConfig Source # 
Instance details

Defined in Hyperion.Database.HasDB

class HasDB env where Source #

HasDB typeclass

Methods

dbConfigLens :: Lens' env DatabaseConfig Source #

Instances

Instances details
HasDB DatabaseConfig Source # 
Instance details

Defined in Hyperion.Database.HasDB

HasDB ClusterEnv Source #

ClusterEnv is an instance of HasDB since it contains info that is sufficient to build a DatabaseConfig.

Instance details

Defined in Hyperion.Cluster

HasDB JobEnv Source #

Make JobEnv an instance of HasDB.

Instance details

Defined in Hyperion.Job

type Pool = Pool Connection Source #

newDefaultPool :: FilePath -> IO (Pool Connection) Source #

Produces a default pool with connections to the SQLite DB in the given file

withConnection :: forall m env a. (MonadIO m, MonadReader env m, HasDB env) => (Connection -> IO a) -> m a Source #

Extracts the connection pool from the environment of our monad, gets a connection and runs the supplied function with it

withConnectionRetry :: forall m env a. (MonadIO m, MonadReader env m, HasDB env, MonadCatch m) => (Connection -> IO a) -> m a Source #

Tries withConnection until succeeds. Failure means that SQLError is thrown during execution of the function. Otherwise execution is deemed successful. The number of attempts is determined by DatabaseConfig in the environment. If last attempt is a failure, the last exception propagates outside of withConnectionRetry. Uses retryRepeated internally.