]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Private.hs
[CONFIG] Start server and DB connexion with Ini file (added to the repo for tests).
[gargantext.git] / src / Gargantext / Database / Private.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE FlexibleContexts #-}
3
4 module Gargantext.Database.Private where
5
6 import qualified Database.PostgreSQL.Simple as PGS
7
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)
16
17 -- TODO add a reader Monad here
18 -- read this in the init file
19
20 databaseParameters :: FilePath -> IO PGS.ConnectInfo
21 databaseParameters fp = do
22 ini <- readIniFile fp
23 let ini'' = case ini of
24 Left e -> panic (pack $ "No ini file error" <> show e)
25 Right ini' -> ini'
26
27 let val x = case (lookupValue (pack "django") (pack x) ini'') of
28 Left _ -> panic (pack $ "no" <> x)
29 Right p' -> unpack p'
30
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" }
36
37
38