Make use of change set

This commit is contained in:
wqy
2022-09-06 21:36:20 +08:00
parent c99a1d728b
commit 3a694d5e03
3 changed files with 50 additions and 14 deletions

View File

@@ -1,13 +1,14 @@
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) -> None:
def set_title(name: str, value: str) -> ChangeSet:
old = get_title(name)
with conn[name].cursor() as cur:
@@ -17,3 +18,7 @@ def set_title(name: str, value: str) -> None:
redo = sql.replace("'", '"')
undo = f'update title set value = "{old}"'
add_operation(name, redo, undo)
change = ChangeSet()
change.update('title', 'null', 'value')
return change