Show connected nodes

This commit is contained in:
Magnus Åhall 2025-07-07 21:44:09 +02:00
parent c3f8bedea1
commit dff17cad5b
7 changed files with 212 additions and 6 deletions

48
node.go
View file

@ -211,7 +211,7 @@ func DeleteNode(nodeID int) (err error) { // {{{
}
return
} // }}}
func MoveNodes(newParentID int, nodeIDs []int) (err error) {
func MoveNodes(newParentID int, nodeIDs []int) (err error) { // {{{
// TODO - implement a method to verify that a node isn't moved underneath itself.
// Preferably using a stored procedure?
@ -230,6 +230,50 @@ func MoveNodes(newParentID int, nodeIDs []int) (err error) {
_, err = db.Exec(sql, newParentID)
return
}
} // }}}
func GetNodeConnections(nodeID int) (connections []Node, err error) { // {{{
connections = []Node{}
var rows *sqlx.Rows
rows, err = db.Queryx(`
SELECT
n.*,
t.id AS type_id,
t.name AS type_name,
t.schema AS type_schema_raw,
t.schema->>'icon' AS type_icon
FROM public.connection c
INNER JOIN public.node n ON c.to = n.id
INNER JOIN public.type t ON n.type_id = t.id
WHERE
c.from = $1
`,
nodeID,
)
if err != nil {
err = werr.Wrap(err)
return
}
defer rows.Close()
for rows.Next() {
var node Node
err = rows.StructScan(&node)
if err != nil {
err = werr.Wrap(err)
return
}
err = json.Unmarshal(node.TypeSchemaRaw, &node.TypeSchema)
if err != nil {
err = werr.Wrap(err)
return
}
connections = append(connections, node)
}
return
} // }}}
// vim: foldmethod=marker