Refine api to support one batch command
This commit is contained in:
@@ -51,7 +51,7 @@ class Junction(object):
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
|
||||
|
||||
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def set_junction_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
old = Junction(get_junction(name, cs.operations[0]['id']))
|
||||
raw_new = get_junction(name, cs.operations[0]['id'])
|
||||
|
||||
@@ -71,10 +71,14 @@ def set_junction(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_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_junction_cache(name, cs))
|
||||
|
||||
|
||||
def add_junction_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
new = Junction(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into _node (id, type) values ({new.f_id}, {new.f_type});"
|
||||
@@ -88,10 +92,14 @@ def add_junction(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_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_junction_cache(name, cs))
|
||||
|
||||
|
||||
def delete_junction_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
old = Junction(get_junction(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from coordinates where node = {old.f_id};"
|
||||
@@ -105,4 +113,8 @@ def delete_junction(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_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_junction_cache(name, cs))
|
||||
|
||||
Reference in New Issue
Block a user