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:

View File

@@ -4,21 +4,25 @@ from _0_base import *
open_project("net")
add_node("net", "n-1", JUNCTION)
print(get_node("net", "n-1"))
if have_node("net", "n-1"):
delete_node("net", "n-1")
print(have_node("net", "n-1"))
add_link("net", "l-1", PIPE)
print(get_link("net", "l-1"))
if have_link("net", "l-1"):
delete_link("net", "l-1")
print(have_link("net", "l-1"))
add_curve("net", "c-1")
print(get_curve("net", "c-1"))
if have_curve("net", "c-1"):
delete_curve("net", "c-1")
print(have_curve("net", "c-1"))
add_pattern("net", "p-1")
print(get_pattern("net", "p-1"))
if have_pattern("net", "p-1"):
delete_pattern("net", "p-1")
print(have_pattern("net", "p-1"))