Guard junction

This commit is contained in:
WQY\qiong
2023-03-22 20:47:16 +08:00
parent 5e69ada90b
commit e68154ea0b
2 changed files with 19 additions and 1 deletions

View File

@@ -12,7 +12,9 @@ def get_junction_schema(name: str) -> dict[str, dict[str, Any]]:
def get_junction(name: str, id: str) -> dict[str, Any]:
j = read(name, f"select * from junctions where id = '{id}'")
j = try_read(name, f"select * from junctions where id = '{id}'")
if j == None:
return {}
xy = get_node_coord(name, id)
d = {}
d['id'] = str(j['id'])
@@ -67,6 +69,10 @@ def set_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_junction(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, set_junction_cmd(name, cs))
@@ -88,6 +94,10 @@ def add_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_junction(name, cs.operations[0]['id']) != {}:
return ChangeSet()
return execute_command(name, add_junction_cmd(name, cs))
@@ -109,6 +119,10 @@ def delete_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_junction(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, delete_junction_cmd(name, cs))