Commit a026a549 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] Sugar to connect to database in REPL.

parent 45a0c499
......@@ -27,10 +27,11 @@ import System.IO (putStrLn, readFile)
import Data.Text (Text(), pack)
import Database.PostgreSQL.Simple (Connection)
import Gargantext.Prelude
import Gargantext.Types.Main (Node, NodeId, NodeType)
import Gargantext.Types.Main (Node, NodeId, NodeType, FacetDoc)
import Gargantext.Database.Node (getNodesWithParentId
, getNode, getNodesWith
, deleteNode, deleteNodes)
, deleteNode, deleteNodes
, getDocFacet)
-- | Node API Types management
......@@ -41,15 +42,18 @@ type NodesAPI = Delete '[JSON] Int
type NodeAPI = Get '[JSON] (Node Value)
:<|> Delete '[JSON] Int
-- Example for Document Facet view, to populate the tabular:
-- http://localhost:8008/node/347476/children?type=Document&limit=3
-- /!\ FIXME : nodeType is case sensitive
-- /!\ see NodeTypes in Types/Main.hs
:<|> "children" :> QueryParam "type" NodeType
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> Get '[JSON] [Node Value]
:<|> "facetDoc" :> QueryParam "type" NodeType
:> QueryParam "offset" Int
:> QueryParam "limit" Int
:> Get '[JSON] [FacetDoc Value]
-- Depending on the Type of the Node, we could post
-- New documents for a corpus
-- New map list terms
......@@ -66,8 +70,9 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing)
nodeAPI :: Connection -> NodeId -> Server NodeAPI
nodeAPI conn id = liftIO (getNode conn id)
:<|> deleteNode' conn id
:<|> deleteNode' conn id
:<|> getNodesWith' conn id
:<|> getDocFacet' conn id
:<|> upload
:<|> query
......@@ -84,6 +89,9 @@ getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe In
-> Handler [Node Value]
getNodesWith' conn id nodeType offset limit = liftIO (getNodesWith conn id nodeType offset limit)
getDocFacet' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe Int
-> Handler [FacetDoc Value]
getDocFacet' conn id nodeType offset limit = liftIO (getDocFacet conn id nodeType offset limit)
query :: Text -> Handler Text
query s = pure s
......
......@@ -13,6 +13,7 @@ import Text.Read (read)
import Data.Ini (readIniFile, lookupValue)
import Data.Word (Word16)
import System.IO (FilePath)
import Database.PostgreSQL.Simple (Connection, connect)
-- TODO add a reader Monad here
-- read this in the init file
......@@ -34,5 +35,7 @@ databaseParameters fp = do
, PGS.connectPassword = val "DB_PASS"
, PGS.connectDatabase = val "DB_NAME" }
connectGargandb :: FilePath -> IO Connection
connectGargandb fp = do
parameters <- databaseParameters fp
connect parameters
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment