Code refactor for change set
This commit is contained in:
@@ -40,7 +40,7 @@ class Mixing(object):
|
||||
return { 'type': self.type, 'tank': self.tank }
|
||||
|
||||
|
||||
def set_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
def set_mixing_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Mixing(get_mixing(name, cs.operations[0]['tank']))
|
||||
raw_new = get_mixing(name, cs.operations[0]['tank'])
|
||||
|
||||
@@ -57,14 +57,14 @@ def set_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
redo_cs = g_update_prefix | new.as_dict()
|
||||
undo_cs = g_update_prefix | old.as_dict()
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def set_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_mixing_cache(name, cs))
|
||||
|
||||
|
||||
def add_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
def add_mixing_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Mixing(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into mixing (tank, model, value) values ({new.f_tank}, {new.f_model}, {new.f_value});"
|
||||
@@ -73,14 +73,14 @@ def add_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
redo_cs = g_add_prefix | new.as_dict()
|
||||
undo_cs = g_delete_prefix | new.as_id_dict()
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def add_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_mixing_cache(name, cs))
|
||||
|
||||
|
||||
def delete_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
def delete_mixing_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Mixing(get_mixing(name, cs.operations[0]['tank']))
|
||||
|
||||
redo_sql = f"delete from mixing where tank = {old.f_tank};"
|
||||
@@ -89,7 +89,7 @@ def delete_mixing_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
redo_cs = g_delete_prefix | old.as_id_dict()
|
||||
undo_cs = g_add_prefix | old.as_dict()
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def delete_mixing(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
|
||||
Reference in New Issue
Block a user