requireConnection :: Config -> IO Connection
requireConnection c = do
  host <- lookupDefault (connectHost defaultConnectInfo) c "db.host"
  port <- lookupDefault (connectPort defaultConnectInfo) c "db.port"
  user <- lookupDefault (connectUser defaultConnectInfo) c "db.user"
  pass <- lookupDefault (connectPassword defaultConnectInfo) c "db.password"
  db   <- lookupDefault (connectDatabase defaultConnectInfo) c "db.database"
  connect (ConnectInfo host port user pass db)

-- This can also be achieved with the prisms from Control.Lens
requireConnection :: Config -> IO Connection
requireConnection c = do
  host <- lookupDefault (connectHost defaultConnectInfo) c "db.host"
  port <- lookupDefault (connectPort defaultConnectInfo) c "db.port"
  user <- lookupDefault (connectUser defaultConnectInfo) c "db.user"
  pass <- lookupDefault (connectPassword defaultConnectInfo) c "db.password"
  db   <- lookupDefault (connectDatabase defaultConnectInfo) c "db.database"
  connect (ConnectInfo host port user pass db)

-- This can also be achieved with the prisms from Control.Lens
requireConnection c = do
  host <- lookupDefault (connectHost defaultConnectInfo) c "db.host"
  port <- lookupDefault (connectPort defaultConnectInfo) c "db.port"
  user <- lookupDefault (connectUser defaultConnectInfo) c "db.user"
  pass <- lookupDefault (connectPassword defaultConnectInfo) c "db.password"
  db   <- lookupDefault (connectDatabase defaultConnectInfo) c "db.database"
  connect (ConnectInfo host port user pass db)

-- This can also be achieved with the prisms from Control.Lens