Files
TJWaterServer/api/s1_title.py
2022-09-07 20:53:55 +08:00

25 lines
735 B
Python

from psycopg.rows import dict_row
from .operation import *
from .connection import g_conn_dict as conn
from .change_set import ChangeSet
def get_title(name: str) -> str:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(f"select * from title")
return cur.fetchone()['value']
def set_title(name: str, value: str) -> ChangeSet:
old = get_title(name)
with conn[name].cursor() as cur:
sql = f"update title set value = '{value}'"
cur.execute(sql)
redo = sql.replace("'", '"')
undo = f'update title set value = "{old}"'
add_operation(name, redo, undo)
change = ChangeSet()
change.update('title', 'null', 'value', 'str', value)
return change