Commit 0e129af0 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[BASHQL] Node' hierarchy (post/get/update semantics to get).

parent bfd3789f
......@@ -82,6 +82,7 @@ type UserId = Int
-- List of NodeId
-- type PWD a = PWD UserId [a]
type PWD = [NodeId]
--data PWD' a = a | PWD' [a]
-- | TODO get Children or Node
get :: Connection -> PWD -> IO [Node Value]
......@@ -145,26 +146,17 @@ ls' = do
h <- home c
ls c h
type Children a = Maybe a
post' :: IO Int64
post' = do
c <- connectGargandb "gargantext.ini"
h <- home c
let userId = 1
-- TODO semantic to achieve
-- post c h [ Corpus "name" "{}" NoChildren
-- , Project "name" "{}" (Children [Corpus "test 2" "" (Children [ Document "title" "metaData" NoChildren
-- , Document "title" "jsonData" NoChildren
-- ]
-- )
-- ]
-- )
-- ]
post c h [ node userId (last h) Corpus "name" "{}"
, node userId (last h) Project "name" "{}"
]
data Children a = NoChildren | Children a
postR' :: IO [Int]
postR' = do
......@@ -176,10 +168,6 @@ postR' = do
]
del' :: [NodeId] -> IO Int
del' ns = do
c <- connectGargandb "gargantext.ini"
......
......@@ -236,9 +236,14 @@ getNodesWithType conn type_id = do
runQuery conn $ selectNodesWithType type_id
type UserId = NodeId
type NodeWrite' = NodePoly (Maybe Int) Int Int (ParentId) Text (Maybe UTCTime) ByteString
type TypeId = Int
------------------------------------------------------------------------
-- Quick and dirty
------------------------------------------------------------------------
type NodeWrite' = NodePoly (Maybe Int) Int Int (ParentId) Text (Maybe UTCTime) ByteString
--node :: UserId -> ParentId -> NodeType -> Text -> Value -> NodeWrite'
node :: UserId -> ParentId -> NodeType -> Text -> Value -> NodeWrite'
node userId parentId nodeType name nodeData = Node Nothing typeId userId parentId name Nothing byteData
......@@ -259,9 +264,60 @@ node2write pid (Node id tn ud _ nm dt hp) = ((pgInt4 <$> id)
mkNode :: Connection -> ParentId -> [NodeWrite'] -> IO Int64
mkNode conn pid ns = runInsertMany conn nodeTable' $ map (node2write pid) ns
mkNodeR :: Connection -> ParentId -> [NodeWrite'] -> IO [Int]
mkNodeR conn pid ns = runInsertManyReturning conn nodeTable' (map (node2write pid) ns) (\(i,_,_,_,_,_,_) -> i)
------------------------------------------------------------------------
-- TODO Hierachy of Nodes
-- post and get same types Node' and update if changes
{- TODO semantic to achieve
post c uid pid [ Node' Corpus "name" "{}" []
, Node' Folder "name" "{}" [Node' Corpus "test 2" "" [ Node' Document "title" "metaData" []
, Node' Document "title" "jsonData" []
]
]
]
-}
------------------------------------------------------------------------
-- TODO
-- currently this function remove the child relation
-- needs a Temporary type between Node' and NodeWriteT
node2table' :: UserId -> ParentId -> Node' -> [NodeWriteT]
node2table' uid pid (Node' nt txt v []) = [( Nothing, (pgInt4$ nodeTypeId nt), (pgInt4 uid), (pgInt4 pid)
, pgStrictText txt, Nothing, pgStrictJSONB $ DB.pack $ DBL.unpack $ encode v)]
node2table' uid pid (Node' nt txt v (c:cs)) = node2table' uid pid (Node' nt txt v [])
<> node2table' uid pid c
<> node2table' uid pid (Node' nt txt v cs)
nodes2table :: UserId -> ParentId -> [Node'] -> [[NodeWriteT]]
nodes2table _ _ [] = []
nodes2table uid pid ns = map (node2table' uid pid) ns
data Node' = Node' { _n_type :: NodeType
, _n_name :: Text
, _n_data :: Value
, _n_children :: [Node']
} deriving (Show)
type NodeWriteT = ( Maybe (Column PGInt4)
, Column PGInt4, Column PGInt4
, Column PGInt4, Column PGText
, Maybe (Column PGTimestamptz)
, Column PGJsonb
)
mkNode' :: Connection -> [NodeWriteT] -> IO Int64
mkNode' conn ns = runInsertMany conn nodeTable' ns
mkNodeR' :: Connection -> [NodeWriteT] -> IO [Int]
mkNodeR' conn ns = runInsertManyReturning conn nodeTable' ns (\(i,_,_,_,_,_,_) -> i)
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