Support cascade deletion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .operation import *
|
||||
from .database import *
|
||||
from .s0_base import *
|
||||
from .s24_coordinates import *
|
||||
|
||||
@@ -75,7 +75,7 @@ class Tank(object):
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
|
||||
|
||||
def set_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Tank(get_tank(name, cs.operations[0]['id']))
|
||||
raw_new = get_tank(name, cs.operations[0]['id'])
|
||||
|
||||
@@ -99,10 +99,10 @@ def set_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_tank_cache(name, cs))
|
||||
return execute_command(name, set_tank_cmd(name, cs))
|
||||
|
||||
|
||||
def add_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Tank(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into _node (id, type) values ({new.f_id}, {new.f_type});"
|
||||
@@ -120,10 +120,10 @@ def add_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_tank_cache(name, cs))
|
||||
return execute_command(name, add_tank_cmd(name, cs))
|
||||
|
||||
|
||||
def delete_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def delete_tank_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Tank(get_tank(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from coordinates where node = {old.f_id};"
|
||||
@@ -141,7 +141,7 @@ def delete_tank_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_tank(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_tank_cache(name, cs))
|
||||
return execute_command(name, delete_tank_cmd(name, cs))
|
||||
|
||||
|
||||
class InpTank:
|
||||
@@ -191,3 +191,13 @@ def inp_out_tank(name: str) -> list[str]:
|
||||
desc = ';'
|
||||
lines.append(f'{id} {elevation} {init_level} {min_level} {max_level} {diameter} {min_vol} {vol_curve} {overflow} {desc}')
|
||||
return lines
|
||||
|
||||
|
||||
def unset_tank_by_curve(name: str, curve: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from tanks where vol_curve = '{curve}'")
|
||||
for row in rows:
|
||||
cs.append(g_update_prefix | {'type': 'tank', 'id': row['id'], 'vol_curve': None})
|
||||
|
||||
return cs
|
||||
|
||||
Reference in New Issue
Block a user