Skip to content

Instantly share code, notes, and snippets.

@thoughtpolice
Last active July 21, 2018 16:59
Show Gist options
  • Save thoughtpolice/e89d370f91039774f98bccf21e0cd877 to your computer and use it in GitHub Desktop.
Save thoughtpolice/e89d370f91039774f98bccf21e0cd877 to your computer and use it in GitHub Desktop.
Opaleye + resource-pool + postgresql-simple
-- | 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
@peterbecich
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment