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

@@ -61,7 +61,7 @@ class Pipe(object):
return { 'type': self.type, 'id': self.id }
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
def set_pipe_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
old = Pipe(get_pipe(name, cs.operations[0]['id']))
raw_new = get_pipe(name, cs.operations[0]['id'])
@@ -78,10 +78,14 @@ def set_pipe(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_pipe(name: str, cs: ChangeSet) -> ChangeSet:
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_pipe_cache(name, cs))
def add_pipe_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
new = Pipe(cs.operations[0])
redo_sql = f"insert into _link (id, type) values ({new.f_id}, {new.f_type});"
@@ -93,10 +97,14 @@ def add_pipe(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_pipe(name: str, cs: ChangeSet) -> ChangeSet:
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, add_pipe_cache(name, cs))
def delete_pipe_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
old = Pipe(get_pipe(name, cs.operations[0]['id']))
redo_sql = f"delete from pipes where id = {old.f_id};"
@@ -108,4 +116,8 @@ def delete_pipe(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_pipe(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_pipe_cache(name, cs))