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