Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get connection pool options from config file. Bump unordered-containers

dependency.
  • Loading branch information...
commit cf5b75ed8a6c5b027ddf0ef25b99fcb8515b8417 1 parent 6c768d7
@mightybyte authored
View
12 resources/db/devel.cfg
@@ -3,3 +3,15 @@ port = 5432
user = "postgres"
pass = ""
db = "testdb"
+
+# Nmuber of distinct connection pools to maintain. The smallest acceptable
+# value is 1.
+numStripes = 1
+
+# Number of seconds an unused resource is kept open. The smallest acceptable
+# value is 0.5 seconds.
+idleTime = 5
+
+# Maximum number of resources to keep open per stripe. The smallest
+# acceptable value is 1.
+maxResourcesPerStripe = 20
View
2  snaplet-postgresql-simple.cabal
@@ -44,7 +44,7 @@ Library
snap >= 0.9 && < 0.10,
text >= 0.11 && < 0.12,
transformers >= 0.2 && < 0.3,
- unordered-containers >= 0.1.4 && < 0.2
+ unordered-containers >= 0.2 && < 0.3
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
View
6 src/Snap/Snaplet/PostgresqlSimple.hs
@@ -171,7 +171,11 @@ pgsInit = makeSnaplet "postgresql-simple" description datadir $ do
return $ P.ConnectInfo <$> host <*> port <*> user <*> pwd <*> db
let ci = fromMaybe (error $ intercalate "\n" errs) mci
- pool <- liftIO $ createPool (P.connect ci) P.close 1 5 20
+ stripes <- liftIO $ C.lookupDefault 1 config "numStripes"
+ idle <- liftIO $ C.lookupDefault 5 config "idleTime"
+ resources <- liftIO $ C.lookupDefault 20 config "maxResourcesPerStripe"
+ pool <- liftIO $ createPool (P.connect ci) P.close stripes
+ (realToFrac (idle :: Double)) resources
return $ Postgres pool
where
description = "PostgreSQL abstraction"
Please sign in to comment.
Something went wrong with that request. Please try again.