Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
dd2049aa
Commit
dd2049aa
authored
Jan 06, 2025
by
Alfredo Di Napoli
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getNodes function to Database.Query.Table.Node
parent
c429cbb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+12
-2
Children.hs
src/Gargantext/Database/Query/Table/Node/Children.hs
+3
-3
No files found.
src/Gargantext/Database/Query/Table/Node.hs
View file @
dd2049aa
...
...
@@ -28,6 +28,7 @@ module Gargantext.Database.Query.Table.Node
,
getClosestParentIdByType'
,
getCorporaWithParentId
,
getNode
,
getNodes
,
getParent
,
getNodeWith
,
getNodeWithType
...
...
@@ -84,7 +85,7 @@ import Gargantext.Database.Admin.Types.Hyperdata.List ( HyperdataList )
import
Gargantext.Database.Admin.Types.Hyperdata.Prelude
(
Hyperdata
)
import
Gargantext.Database.Prelude
(
DBCmd
,
JSONB
,
mkCmd
,
execPGSQuery
,
runPGSQuery
,
runOpaQuery
)
import
Gargantext.Database.Query.Filter
(
limit'
,
offset'
)
import
Gargantext.Database.Query.Table.Node.Children
(
getChildrenById
)
import
Gargantext.Database.Query.Table.Node.Children
(
getChildrenBy
Parent
Id
)
import
Gargantext.Database.Query.Table.Node.Error
import
Gargantext.Database.Schema.Node
import
Gargantext.Prelude
hiding
(
sum
,
head
)
...
...
@@ -313,6 +314,15 @@ getNode nId = do
Nothing
->
nodeError
(
DoesNotExist
nId
)
Just
r
->
pure
r
-- | Get the nodes recursively, as a hierarchical tree.
getNodes
::
HasNodeError
err
=>
NodeId
->
DBCmd
err
(
Tree
(
Node
Value
))
getNodes
nId
=
do
root
<-
getNode
nId
children
<-
getChildrenByParentId
nId
case
children
of
[]
->
pure
$
TreeN
root
[]
xs
->
TreeN
root
<$>
forM
xs
getNodes
-- | Get the parent of a given 'Node', failing if this was called
-- on a root node.
getParent
::
HasNodeError
err
=>
Node
a
->
DBCmd
err
(
Node
Value
)
...
...
@@ -494,7 +504,7 @@ copyNode copySubtree smart idToCopy newParentId = if copySubtree
then
do
-- Non-recursively copy the node itself, then recursively copy its children:
copiedNode
<-
copyNode
False
smart
idToCopy
newParentId
children
<-
getChildrenById
idToCopy
children
<-
getChildrenBy
Parent
Id
idToCopy
for_
children
$
\
child
->
copyNode
True
smart
child
copiedNode
return
copiedNode
-- Single-node (non-recursive) copy:
...
...
src/Gargantext/Database/Query/Table/Node/Children.hs
View file @
dd2049aa
...
...
@@ -63,9 +63,9 @@ getChildren a b c d e = getChildrenNode a b c d e
-- | Get the list of (IDs of) children of a given node (ID)
getChildrenById
::
NodeId
-- ^ ID of the parent node
->
DBCmd
err
[
NodeId
]
-- ^ List of IDs of the children nodes
getChildrenById
parentId
=
runPGSQuery
getChildrenBy
Parent
Id
::
NodeId
-- ^ ID of the parent node
->
DBCmd
err
[
NodeId
]
-- ^ List of IDs of the children nodes
getChildrenBy
Parent
Id
parentId
=
runPGSQuery
[
sql
|
SELECT id FROM public.nodes WHERE parent_id = ?;
|]
parentId
...
...
Przemyslaw Kaminski
@cgenie
mentioned in commit
942e663f
·
Jan 29, 2025
mentioned in commit
942e663f
mentioned in commit 942e663f539b287b4cc0469fe2bcf735813b4ff2
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment