Guard pattern and curve

This commit is contained in:
WQY\qiong
2023-03-22 21:16:50 +08:00
parent 7a2a52b920
commit 4c4a03fcb0
3 changed files with 34 additions and 1 deletions

View File

@@ -11,6 +11,9 @@ def get_pattern_schema(name: str) -> dict[str, dict[str, Any]]:
def get_pattern(name: str, id: str) -> dict[str, Any]:
p_one = try_read(name, f"select * from _pattern where id = '{id}'")
if p_one == None:
return {}
pas = read_all(name, f"select * from patterns where id = '{id}' order by _order")
ps = []
for r in pas:
@@ -46,6 +49,10 @@ def set_pattern_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def set_pattern(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_pattern(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, set_pattern_cmd(name, cs))
@@ -70,6 +77,10 @@ def add_pattern_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def add_pattern(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_pattern(name, cs.operations[0]['id']) != {}:
return ChangeSet()
return execute_command(name, add_pattern_cmd(name, cs))
@@ -94,6 +105,10 @@ def delete_pattern_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_pattern(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, delete_pattern_cmd(name, cs))

View File

@@ -16,7 +16,9 @@ def get_curve_schema(name: str) -> dict[str, dict[str, Any]]:
def get_curve(name: str, id: str) -> dict[str, Any]:
c_one = read(name, f"select * from _curve where id = '{id}'")
c_one = try_read(name, f"select * from _curve where id = '{id}'")
if c_one == None:
return {}
cus = read_all(name, f"select * from curves where id = '{id}' order by _order")
cs = []
for r in cus:
@@ -66,6 +68,10 @@ def set_curve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def set_curve(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_curve(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, set_curve_cmd(name, cs))
@@ -94,6 +100,10 @@ def add_curve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def add_curve(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_curve(name, cs.operations[0]['id']) != {}:
return ChangeSet()
return execute_command(name, add_curve_cmd(name, cs))
@@ -120,6 +130,10 @@ def delete_curve_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
if 'id' not in cs.operations[0]:
return ChangeSet()
if get_curve(name, cs.operations[0]['id']) == {}:
return ChangeSet()
return execute_command(name, delete_curve_cmd(name, cs))