This commit is contained in:
wqy
2022-09-01 22:56:19 +08:00
parent 1c5d0984bf
commit 1fa8a4ac2a
2 changed files with 27 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
from _connection import _conn_dict as conn
from psycopg.rows import dict_row
_NODE = "_NODE"
_LINK = "_LINK"
@@ -52,6 +53,28 @@ def have_pattern(name: str, id: str) -> bool:
return _have_impl(name, id, _PATTERN)
# get
def _get_impl(name: str, id: str, table: str) -> dict[str, str]:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(f"SELECT * FROM {table} WHERE ID = '{id}'")
if cur.rowcount > 0:
return cur.fetchone()
else:
return {}
def get_node(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _NODE)
def get_link(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _LINK)
def get_curve(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _CURVE)
def get_pattern(name: str, id: str) -> dict[str, str]:
return _get_impl(name, id, _PATTERN)
# delete
def _delete_impl(name: str, id: str, table: str) -> None: