-- | DSL for construction of configs.
module Hasql.Pool.Config
  ( Config.Config,
    settings,
    Setting.Setting,
    Setting.size,
    Setting.acquisitionTimeout,
    Setting.agingTimeout,
    Setting.idlenessTimeout,
    Setting.staticConnectionSettings,
    Setting.dynamicConnectionSettings,
    Setting.observationHandler,
  )
where

import qualified Hasql.Pool.Config.Config as Config
import qualified Hasql.Pool.Config.Setting as Setting
import Hasql.Pool.Prelude

-- | Compile config from a list of settings.
-- Latter settings override the preceding in cases of conflicts.
settings :: [Setting.Setting] -> Config.Config
settings :: [Setting] -> Config
settings =
  ((Config -> Config) -> Config -> Config)
-> Config -> [Config -> Config] -> Config
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Config -> Config) -> Config -> Config
forall a b. (a -> b) -> a -> b
($) Config
Config.defaults ([Config -> Config] -> Config)
-> ([Setting] -> [Config -> Config]) -> [Setting] -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (Setting -> Config -> Config) -> [Setting] -> [Config -> Config]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Setting -> Config -> Config
Setting.apply