Support cascade deletion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .operation import *
|
||||
from .database import *
|
||||
|
||||
|
||||
element_schema = {'type': 'str' , 'optional': True , 'readonly': False}
|
||||
@@ -22,7 +22,7 @@ def get_reaction(name: str) -> dict[str, Any]:
|
||||
return d
|
||||
|
||||
|
||||
def set_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_reaction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
raw_old = get_reaction(name)
|
||||
|
||||
old = {}
|
||||
@@ -57,7 +57,7 @@ def set_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_reaction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_reaction_cache(name, cs))
|
||||
return execute_command(name, set_reaction_cmd(name, cs))
|
||||
|
||||
|
||||
def get_pipe_reaction_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
@@ -92,7 +92,7 @@ class PipeReaction(object):
|
||||
return { 'type': self.type, 'pipe': self.pipe, 'bulk': self.bulk, 'wall': self.wall }
|
||||
|
||||
|
||||
def set_pipe_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_pipe_reaction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = PipeReaction(get_pipe_reaction(name, cs.operations[0]['pipe']))
|
||||
raw_new = get_pipe_reaction(name, cs.operations[0]['pipe'])
|
||||
|
||||
@@ -122,7 +122,7 @@ def set_pipe_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_pipe_reaction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_pipe_reaction_cache(name, cs))
|
||||
return execute_command(name, set_pipe_reaction_cmd(name, cs))
|
||||
|
||||
|
||||
def get_tank_reaction_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
@@ -152,7 +152,7 @@ class TankReaction(object):
|
||||
return { 'type': self.type, 'tank': self.tank, 'value': self.value }
|
||||
|
||||
|
||||
def set_tank_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_tank_reaction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = TankReaction(get_tank_reaction(name, cs.operations[0]['tank']))
|
||||
raw_new = get_tank_reaction(name, cs.operations[0]['tank'])
|
||||
|
||||
@@ -178,7 +178,7 @@ def set_tank_reaction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_tank_reaction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_tank_reaction_cache(name, cs))
|
||||
return execute_command(name, set_tank_reaction_cmd(name, cs))
|
||||
|
||||
|
||||
def inp_in_reaction(section: list[str]) -> ChangeSet:
|
||||
@@ -238,4 +238,19 @@ def inp_out_reaction(name: str) -> list[str]:
|
||||
value = obj['value']
|
||||
lines.append(f'TANK {tank} {value}')
|
||||
|
||||
return lines
|
||||
return lines
|
||||
|
||||
|
||||
def delete_pipe_reaction_by_pipe(name: str, pipe: str) -> ChangeSet:
|
||||
row1 = try_read(name, f"select * from reactions_pipe_bulk where pipe = '{pipe}'")
|
||||
row2 = try_read(name, f"select * from reactions_pipe_wall where pipe = '{pipe}'")
|
||||
if row1 == None and row2 == None:
|
||||
return ChangeSet()
|
||||
return ChangeSet(g_update_prefix | {'type': 'pipe_reaction', 'pipe': pipe, 'bulk': None, 'wall': None})
|
||||
|
||||
|
||||
def delete_tank_reaction_by_tank(name: str, tank: str) -> ChangeSet:
|
||||
row = try_read(name, f"select * from reactions_tank where tank = '{tank}'")
|
||||
if row == None:
|
||||
return ChangeSet()
|
||||
return ChangeSet(g_update_prefix | {'type': 'tank_reaction', 'tank': tank, 'value': None})
|
||||
|
||||
Reference in New Issue
Block a user