Files
TJWaterServer/api/_1_title.py
2022-09-01 22:38:01 +08:00

29 lines
914 B
Python

from _connection import _conn_dict as conn
from psycopg.rows import dict_row
def have_title(name: str) -> bool:
with conn[name].cursor() as cur:
cur.execute(f"SELECT * FROM TITLE")
return cur.rowcount > 0
def set_title(name: str, value: str) -> None:
if have_title(name):
with conn[name].cursor() as cur:
cur.execute(f"UPDATE TITLE SET Value = '{value}'")
else:
with conn[name].cursor() as cur:
cur.execute(f"INSERT INTO TITLE (Value) VALUES ('{value}')")
def get_title(name: str) -> str:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(f"SELECT * FROM TITLE")
if cur.rowcount > 0:
return cur.fetchone()['value']
else:
return ""
def unset_title(name: str) -> None:
with conn[name].cursor() as cur:
cur.execute(f"TRUNCATE TITLE")
return cur.rowcount > 0