Last active
December 6, 2022 02:43
-
-
Save ahaxu/a847f0d6655d95ded85996f9a38be09f to your computer and use it in GitHub Desktop.
haskell_connect_db_with_options.hs
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
import Database.PostgreSQL.Simple | |
import System.Environment | |
import Database.PostgreSQL.Simple.Options | |
getDBConn :: IO Connection | |
getDBConn = do | |
-- get db info | |
hostName <- getEnv "DB_HOST" | |
dbName <- getEnv "DB_NAME" | |
userName <- getEnv "DB_USER" | |
dbPassword <- getEnv "DB_PASSWORD" | |
let | |
connOpts :: Options | |
connOpts = mempty | |
{ host = pure hostName | |
, user = pure userName | |
, dbname = pure dbName | |
, password = pure dbPassword | |
, port = pure 5432 | |
} | |
connectPostgreSQL $ toConnectionString connOpts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment