Skip to content

Commit

Permalink
Add defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-volkov committed Feb 27, 2024
1 parent d34ab0a commit 77041bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions hasql-pool.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ library
exposed-modules:
Hasql.Pool
Hasql.Pool.Config
Hasql.Pool.Config.Defaults
Hasql.Pool.Observation

-- cabal-gild: discover src/library/other
Expand Down
40 changes: 40 additions & 0 deletions src/library/exposed/Hasql/Pool/Config/Defaults.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Hasql.Pool.Config.Defaults where

import qualified Hasql.Connection as Connection
import Hasql.Pool.Observation (Observation)
import Hasql.Pool.Prelude

-- |
-- 3 connections.
size :: Int
size = 3

-- |
-- 10 seconds.
acquisitionTimeout :: DiffTime
acquisitionTimeout = 10

-- |
-- 1 day.
agingTimeout :: DiffTime
agingTimeout = 60 * 60 * 24

-- |
-- 10 minutes.
idlenessTimeout :: DiffTime
idlenessTimeout = 60 * 10

-- |
-- > "postgresql://postgres:postgres@localhost:5432/postgres"
staticConnectionSettings :: Connection.Settings
staticConnectionSettings = "postgresql://postgres:postgres@localhost:5432/postgres"

-- |
-- > pure "postgresql://postgres:postgres@localhost:5432/postgres"
dynamicConnectionSettings :: IO Connection.Settings
dynamicConnectionSettings = pure "postgresql://postgres:postgres@localhost:5432/postgres"

-- |
-- > const (pure ())
observationHandler :: Observation -> IO ()
observationHandler = const (pure ())
13 changes: 7 additions & 6 deletions src/library/other/Hasql/Pool/Config/Config.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Hasql.Pool.Config.Config where

import qualified Hasql.Connection as Connection
import qualified Hasql.Pool.Config.Defaults as Defaults
import Hasql.Pool.Observation (Observation)
import Hasql.Pool.Prelude

Expand All @@ -18,10 +19,10 @@ data Config = Config
defaults :: Config
defaults =
Config
{ size = 3,
acquisitionTimeout = 10,
agingTimeout = 60 * 60 * 24,
idlenessTimeout = 60 * 10,
connectionSettingsProvider = pure "postgresql://postgres:postgres@localhost:5432/postgres",
observationHandler = const (pure ())
{ size = Defaults.size,
acquisitionTimeout = Defaults.acquisitionTimeout,
agingTimeout = Defaults.agingTimeout,
idlenessTimeout = Defaults.idlenessTimeout,
connectionSettingsProvider = Defaults.dynamicConnectionSettings,
observationHandler = Defaults.observationHandler
}

0 comments on commit 77041bb

Please sign in to comment.