From 345ce9a98de089851f6feffe36e7767932456c7c Mon Sep 17 00:00:00 2001 From: wqy Date: Thu, 22 Sep 2022 21:05:30 +0800 Subject: [PATCH] Get link of node --- api/s0_base.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/s0_base.py b/api/s0_base.py index bedcd28..c966e66 100644 --- a/api/s0_base.py +++ b/api/s0_base.py @@ -179,3 +179,15 @@ def delete_link(name: str, link_type: str, id: str, table_sql: str, table_undo_s change = ChangeSet() change.delete(link_type, id) return change + + +def get_node_links(name: str, id: str) -> list[str]: + with conn[name].cursor(row_factory=dict_row) as cur: + links: list[str] = [] + for p in cur.execute(f"select id from pipes where node1 = '{id}' or node2 = '{id}'").fetchall(): + links.append(p['id']) + for p in cur.execute(f"select id from pumps where node1 = '{id}' or node2 = '{id}'").fetchall(): + links.append(p['id']) + for p in cur.execute(f"select id from valves where node1 = '{id}' or node2 = '{id}'").fetchall(): + links.append(p['id']) + return links