runConnectionPool :: MonadControlIO m => SqlPersist m a -> ConnectionPool -> m a runConnectionPool = runSqlPool withConnectionPool :: MonadControlIO m => AppConfig -> (ConnectionPool -> m a) -> m a withConnectionPool conf f = do cs <- liftIO $ loadConnStr (appEnv conf) with~upper~Pool cs (connectionPoolSize conf) f where -- | The database connection string. The meaning of this string is backend- -- specific. loadConnStr :: AppEnvironment -> IO Text loadConnStr env = do allSettings <- (join $ YAML.decodeFile ("config/~backendLower~.yml" :: String)) >>= fromMapping settings <- lookupMapping (show env) allSettings database <- lookupScalar "database" settings :: IO Text connPart <- fmap concat $ (flip mapM) ["user", "password", "host", "port"] $ \key -> do value <- lookupScalar key settings return $ [st| #{key}=#{value} |] return $ [st|#{connPart} dbname=#{database}|] -- Example of making a dynamic configuration static -- use /return $(mkConnStr Production)/ instead of loadConnStr -- mkConnStr :: AppEnvironment -> Q Exp -- mkConnStr env = qRunIO (loadConnStr env) >>= return . LitE . StringL