Get base
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user