Guard pipe
This commit is contained in:
@@ -19,7 +19,9 @@ def get_pipe_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
|
||||
|
||||
def get_pipe(name: str, id: str) -> dict[str, Any]:
|
||||
p = read(name, f"select * from pipes where id = '{id}'")
|
||||
p = try_read(name, f"select * from pipes where id = '{id}'")
|
||||
if p == None:
|
||||
return {}
|
||||
d = {}
|
||||
d['id'] = str(p['id'])
|
||||
d['node1'] = str(p['node1'])
|
||||
@@ -82,6 +84,10 @@ def set_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_pipe(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, set_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -101,6 +107,10 @@ def add_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_pipe(name, cs.operations[0]['id']) != {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, add_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
@@ -120,6 +130,10 @@ def delete_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
if 'id' not in cs.operations[0]:
|
||||
return ChangeSet()
|
||||
if get_pipe(name, cs.operations[0]['id']) == {}:
|
||||
return ChangeSet()
|
||||
return execute_command(name, delete_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user