Last active
July 21, 2018 16:59
-
-
Save thoughtpolice/e89d370f91039774f98bccf21e0cd877 to your computer and use it in GitHub Desktop.
Opaleye + resource-pool + postgresql-simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Simple alias for PostgreSQL connection pools. | |
type PostgresPool = Pool.Pool PGS.Connection | |
-- | Execute a query against the PostgreSQL database, using | |
-- a connection pool. | |
runQueryPool :: Default QueryRunner cols vals | |
=> Pool.Pool PGS.Connection | |
-> Query cols | |
-> IO [vals] | |
runQueryPool p q = Pool.withResource p (`runQuery` q) | |
-- | Create a @'PostgresPool'@ connection pool. | |
createPostgresPool :: Maybe PGS.ConnectInfo | |
-- ^ Optional connection information. | |
-> Int | |
-- ^ Number of stripes. | |
-> Time.NominalDiffTime | |
-- ^ Time to keep unused connections open. | |
-> Int | |
-- ^ Maximum connections per stripe. | |
-> IO PostgresPool | |
createPostgresPool connInfo = go where | |
go = Pool.createPool (PGS.connectPostgreSQL info) PGS.close | |
info = PGS.postgreSQLConnectionString | |
$ fromMaybe PGS.defaultConnectInfo connInfo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!