Add api to query type

This commit is contained in:
wqy
2022-09-02 19:01:59 +08:00
parent d90f7d6f8e
commit 49bea820b8
3 changed files with 37 additions and 1 deletions

View File

@@ -34,7 +34,7 @@ def _query_redo(name: str, id: str) -> dict[str, str]:
cur.execute(f"select redo from operation where id = {id}")
return cur.fetchone()['redo']
def _set_redo_child(name: str, id: str, child:str) -> None:
def _set_redo_child(name: str, id: str, child: str) -> None:
with conn[name].cursor() as cur:
cur.execute(f"update operation set redo_child = {child} where id = {id}")

View File

@@ -78,9 +78,27 @@ def _get_impl(name: str, id: str, table: str) -> dict[str, str]:
def get_node(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _NODE)
def is_junction(name: str, id: str) -> bool:
return get_node(name, id)['type'] == JUNCTION
def is_reservoir(name: str, id: str) -> bool:
return get_node(name, id)['type'] == RESERVOIR
def is_tank(name: str, id: str) -> bool:
return get_node(name, id)['type'] == TANK
def get_link(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _LINK)
def is_pipe(name: str, id: str) -> bool:
return get_link(name, id)['type'] == PIPE
def is_pump(name: str, id: str) -> bool:
return get_link(name, id)['type'] == PUMP
def is_valve(name: str, id: str) -> bool:
return get_link(name, id)['type'] == VALVE
def get_curve(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _CURVE)

View File

@@ -40,6 +40,15 @@ def add_node(name: str, node_id: str, node_type: str) -> None:
def have_node(name: str, node_id: str) -> bool:
return _0.have_node(name, node_id)
def is_junction(name: str, node_id: str) -> bool:
return _0.is_junction(name, node_id)
def is_reservoir(name: str, node_id: str) -> bool:
return _0.is_reservoir(name, node_id)
def is_tank(name: str, node_id: str) -> bool:
return _0.is_tank(name, node_id)
def delete_node(name: str, node_id: str) -> None:
return _0.delete_node(name, node_id)
@@ -49,6 +58,15 @@ def add_link(name: str, link_id: str, link_type: str) -> None:
def have_link(name: str, link_id: str) -> bool:
return _0.have_link(name, link_id)
def is_pipe(name: str, link_id: str) -> bool:
return _0.is_pipe(name, link_id)
def is_pump(name: str, link_id: str) -> bool:
return _0.is_pump(name, link_id)
def is_valve(name: str, link_id: str) -> bool:
return _0.is_valve(name, link_id)
def delete_link(name: str, link_id: str) -> None:
return _0.delete_link(name, link_id)