Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

thoughtbot/persistent-database-url

Repository files navigation

persistent-database-url

Converts the parameters parsed from a database url to the concrete configuration types required by persistent.

Currently, only persistent-postgresql's PostgresConf is provided.

Installation

cabal install persistent-database-url

Example Usage

Adjusting the Yesod scaffold to run on Heroku:

config/settings.yml

database-url: "_env:DATABASE_URL:postgres://user:pass@localhost:5432/dbname"
database-pool-size: "_env:DB_POOL:5"

Settings.hs:

import Database.Persist.URL (fromDatabaseUrl)

instance FromJSON AppSettings where
    parseJSON = withObject "AppSettings" $ \o -> do
        appDatabaseConf <- fromDatabaseUrl
                             <$> o .: "database-pool-size"
                             <*> o .: "database-url"
        -- ...

        return AppSettings {..}

How to run tests

stack test

About

Parse database urls into the concrete configuration types required by Persistent

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published