Refine api to support one batch command

This commit is contained in:
WQY\qiong
2022-10-26 19:35:04 +08:00
parent 78d7be1d9a
commit 65e2ce2541
16 changed files with 182 additions and 178 deletions

View File

@@ -52,7 +52,7 @@ class Pump(object):
return { 'type': self.type, 'id': self.id }
def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
def set_pump_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
old = Pump(get_pump(name, cs.operations[0]['id']))
raw_new = get_pump(name, cs.operations[0]['id'])
@@ -69,10 +69,14 @@ def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
redo_cs = g_update_prefix | new.as_dict()
undo_cs = g_update_prefix | old.as_dict()
return execute_command(name, redo_sql, undo_sql, redo_cs, undo_cs)
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_pump_cache(name, cs))
def add_pump_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
new = Pump(cs.operations[0])
redo_sql = f"insert into _link (id, type) values ({new.f_id}, {new.f_type});"
@@ -84,10 +88,14 @@ def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
redo_cs = g_add_prefix | new.as_dict()
undo_cs = g_delete_prefix | new.as_id_dict()
return execute_command(name, redo_sql, undo_sql, redo_cs, undo_cs)
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, add_pump_cache(name, cs))
def delete_pump_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
old = Pump(get_pump(name, cs.operations[0]['id']))
redo_sql = f"delete from pumps where id = {old.f_id};"
@@ -99,4 +107,8 @@ def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
redo_cs = g_delete_prefix | old.as_id_dict()
undo_cs = g_add_prefix | old.as_dict()
return execute_command(name, redo_sql, undo_sql, redo_cs, undo_cs)
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_pump_cache(name, cs))