1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE FlexibleContexts #-}
4 module Gargantext.Database.Private where
6 import qualified Database.PostgreSQL.Simple as PGS
8 import Data.Monoid ((<>))
9 import Data.Either.Extra (Either(Left, Right))
10 import Gargantext.Prelude
11 import Data.Text (unpack, pack)
12 import Text.Read (read)
13 import Data.Ini (readIniFile, lookupValue)
14 import Data.Word (Word16)
15 import System.IO (FilePath)
17 -- TODO add a reader Monad here
18 -- read this in the init file
20 databaseParameters :: FilePath -> IO PGS.ConnectInfo
21 databaseParameters fp = do
23 let ini'' = case ini of
24 Left e -> panic (pack $ "No ini file error" <> show e)
27 let val x = case (lookupValue (pack "django") (pack x) ini'') of
28 Left _ -> panic (pack $ "no" <> x)
31 pure $ PGS.ConnectInfo { PGS.connectHost = val "DB_HOST"
32 , PGS.connectPort = read (val "DB_PORT") :: Word16
33 , PGS.connectUser = val "DB_USER"
34 , PGS.connectPassword = val "DB_PASS"
35 , PGS.connectDatabase = val "DB_NAME" }