heroku 0.1 → 0.1.1
raw patch · 4 files changed
+35/−40 lines, 4 files
Files
- Web/Heroku.hs +1/−38
- Web/Heroku/MongoDB.hs +17/−0
- Web/Heroku/Postgres.hs +13/−0
- heroku.cabal +4/−2
Web/Heroku.hs view
@@ -7,41 +7,4 @@ import Network.URI import Data.Text import Prelude---- | read the DATABASE_URL environment variable--- and return an alist of connection parameters with the following keys:--- user, password, host, port, dbname------ warning: just calls error if it can't parse correctly-dbConnParams :: IO [(Text, Text)]-dbConnParams = getEnv "DATABASE_URL" >>= return . parseDatabaseUrl--parseDatabaseUrl :: String -> [(Text, Text)]-parseDatabaseUrl durl =- let muri = parseAbsoluteURI durl- (auth, path) = case muri of- Nothing -> error "couldn't parse absolute uri"- Just uri -> if uriScheme uri /= "postgres:"- then schemeError uri- else case uriAuthority uri of- Nothing -> invalid- Just a -> (a, uriPath uri)- (user,password) = userAndPassword auth- in [- (pack "user", user)- -- tail not safe, but should be there on Heroku- ,(pack "password", Data.Text.tail password)- ,(pack "host", pack $ uriRegName auth)- -- Heroku should use default port- -- ,(pack "port", pack $ uriPort auth)- -- tail not safe but path should always be there- ,(pack "dbname", pack $ Prelude.tail $ path)- ]- where- -- init is not safe, but should be there on Heroku- userAndPassword :: URIAuth -> (Text, Text)- userAndPassword = (breakOn $ pack ":") . pack . Prelude.init . uriUserInfo-- schemeError uri = error $ "was expecting a postgres scheme, not: " ++ (uriScheme uri) ++ "\n" ++ (show uri)- -- should be an error - invalid = error "could not parse heroku DATABASE_URL"+import Web.Heroku.Postgres (dbConnParams, parseDatabaseUrl)
+ Web/Heroku/MongoDB.hs view
@@ -0,0 +1,17 @@+module Web.Heroku.MongoDB ( + mongoLabConnParams+ , mongoHQConnParams+ , parseDatabaseUrl+ ) where++import Data.Text+import Web.Heroku.Internal (dbConnParams', parseDatabaseUrl')++mongoLabConnParams :: IO [(Text, Text)]+mongoLabConnParams = dbConnParams' "MONGOLAB_URI" parseDatabaseUrl++mongoHQConnParams :: IO [(Text, Text)]+mongoHQConnParams = dbConnParams' "MONGOHQ_URL" parseDatabaseUrl++parseDatabaseUrl :: String -> [(Text, Text)]+parseDatabaseUrl = parseDatabaseUrl' "mongodb:"
+ Web/Heroku/Postgres.hs view
@@ -0,0 +1,13 @@+module Web.Heroku.Postgres ( + dbConnParams + , parseDatabaseUrl+ ) where++import Data.Text+import Web.Heroku.Internal (dbConnParams', parseDatabaseUrl')++dbConnParams :: IO [(Text, Text)]+dbConnParams = dbConnParams' "DATABASE_URL" parseDatabaseUrl++parseDatabaseUrl :: String -> [(Text, Text)]+parseDatabaseUrl = parseDatabaseUrl' "postgres:"
heroku.cabal view
@@ -1,5 +1,5 @@ Name: heroku-Version: 0.1+Version: 0.1.1 Synopsis: helpers for deploying to Heroku Description: currently just a parser for DATABASE_URL Homepage: https://github.com/gregwebs/haskell-heroku@@ -14,7 +14,9 @@ Library- Exposed-modules: Web.Heroku+ Exposed-modules: Web.Heroku+ , Web.Heroku.Postgres+ , Web.Heroku.MongoDB Build-depends: base >= 4 && < 5 , text