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

[FEAT] Sugar to connect to database in REPL.

parent 96cf6b63
...@@ -27,10 +27,11 @@ import System.IO (putStrLn, readFile) ...@@ -27,10 +27,11 @@ import System.IO (putStrLn, readFile)
import Data.Text (Text(), pack) import Data.Text (Text(), pack)
import Database.PostgreSQL.Simple (Connection) import Database.PostgreSQL.Simple (Connection)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Types.Main (Node, NodeId, NodeType) import Gargantext.Types.Main (Node, NodeId, NodeType, FacetDoc)
import Gargantext.Database.Node (getNodesWithParentId import Gargantext.Database.Node (getNodesWithParentId
, getNode, getNodesWith , getNode, getNodesWith
, deleteNode, deleteNodes) , deleteNode, deleteNodes
, getDocFacet)
-- | Node API Types management -- | Node API Types management
...@@ -41,15 +42,18 @@ type NodesAPI = Delete '[JSON] Int ...@@ -41,15 +42,18 @@ type NodesAPI = Delete '[JSON] Int
type NodeAPI = Get '[JSON] (Node Value) type NodeAPI = Get '[JSON] (Node Value)
:<|> Delete '[JSON] Int :<|> 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 :<|> "children" :> QueryParam "type" NodeType
:> QueryParam "offset" Int :> QueryParam "offset" Int
:> QueryParam "limit" Int :> QueryParam "limit" Int
:> Get '[JSON] [Node Value] :> 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 -- Depending on the Type of the Node, we could post
-- New documents for a corpus -- New documents for a corpus
-- New map list terms -- New map list terms
...@@ -66,8 +70,9 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing) ...@@ -66,8 +70,9 @@ roots conn = liftIO (getNodesWithParentId conn 0 Nothing)
nodeAPI :: Connection -> NodeId -> Server NodeAPI nodeAPI :: Connection -> NodeId -> Server NodeAPI
nodeAPI conn id = liftIO (getNode conn id) nodeAPI conn id = liftIO (getNode conn id)
:<|> deleteNode' conn id :<|> deleteNode' conn id
:<|> getNodesWith' conn id :<|> getNodesWith' conn id
:<|> getDocFacet' conn id
:<|> upload :<|> upload
:<|> query :<|> query
...@@ -84,6 +89,9 @@ getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe In ...@@ -84,6 +89,9 @@ getNodesWith' :: Connection -> NodeId -> Maybe NodeType -> Maybe Int -> Maybe In
-> Handler [Node Value] -> Handler [Node Value]
getNodesWith' conn id nodeType offset limit = liftIO (getNodesWith conn id nodeType offset limit) 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 :: Text -> Handler Text
query s = pure s query s = pure s
......
...@@ -13,6 +13,7 @@ import Text.Read (read) ...@@ -13,6 +13,7 @@ import Text.Read (read)
import Data.Ini (readIniFile, lookupValue) import Data.Ini (readIniFile, lookupValue)
import Data.Word (Word16) import Data.Word (Word16)
import System.IO (FilePath) import System.IO (FilePath)
import Database.PostgreSQL.Simple (Connection, connect)
-- TODO add a reader Monad here -- TODO add a reader Monad here
-- read this in the init file -- read this in the init file
...@@ -34,5 +35,7 @@ databaseParameters fp = do ...@@ -34,5 +35,7 @@ databaseParameters fp = do
, PGS.connectPassword = val "DB_PASS" , PGS.connectPassword = val "DB_PASS"
, PGS.connectDatabase = val "DB_NAME" } , 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