Guard pattern and curve
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user