Code refactor for change set
This commit is contained in:
@@ -16,7 +16,7 @@ def get_vertex(name: str, link: str) -> dict[str, Any]:
|
||||
return { 'link': link, 'coords': cs }
|
||||
|
||||
|
||||
def set_vertex_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
def set_vertex_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
link = cs.operations[0]['link']
|
||||
|
||||
old = get_vertex(name, link)
|
||||
@@ -40,43 +40,38 @@ def set_vertex_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
redo_cs = { 'type': 'vertex' } | new
|
||||
undo_cs = { 'type': 'vertex' } | old
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def add_vertex_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs |= g_add_prefix
|
||||
result.undo_cs |= g_delete_prefix
|
||||
return result
|
||||
|
||||
|
||||
def delete_vertex_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
cs.operations[0]['coords'] = []
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs |= g_delete_prefix
|
||||
result.undo_cs |= g_add_prefix
|
||||
return result
|
||||
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
||||
|
||||
|
||||
def set_vertex(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs |= g_update_prefix
|
||||
result.undo_cs |= g_update_prefix
|
||||
result.redo_cs[0] |= g_update_prefix
|
||||
result.undo_cs[0] |= g_update_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def add_vertex(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def add_vertex_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs |= g_add_prefix
|
||||
result.undo_cs |= g_delete_prefix
|
||||
result.redo_cs[0] |= g_add_prefix
|
||||
result.undo_cs[0] |= g_delete_prefix
|
||||
return result
|
||||
|
||||
|
||||
def delete_vertex_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
cs.operations[0]['coords'] = []
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs[0] |= g_delete_prefix
|
||||
result.undo_cs[0] |= g_add_prefix
|
||||
return result
|
||||
|
||||
|
||||
def add_vertex(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
result = add_vertex_cache(name, cs)
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def delete_vertex(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
cs.operations[0]['coords'] = []
|
||||
result = set_vertex_cache(name, cs)
|
||||
result.redo_cs |= g_delete_prefix
|
||||
result.undo_cs |= g_add_prefix
|
||||
result = delete_vertex_cache(name, cs)
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user