Support cascade deletion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .operation import *
|
||||
from .database import *
|
||||
from .s0_base import *
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class Pump(object):
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
|
||||
|
||||
def set_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Pump(get_pump(name, cs.operations[0]['id']))
|
||||
raw_new = get_pump(name, cs.operations[0]['id'])
|
||||
|
||||
@@ -73,10 +73,10 @@ def set_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_pump_cache(name, cs))
|
||||
return execute_command(name, set_pump_cmd(name, cs))
|
||||
|
||||
|
||||
def add_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Pump(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into _link (id, type) values ({new.f_id}, {new.f_type});"
|
||||
@@ -92,10 +92,10 @@ def add_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_pump_cache(name, cs))
|
||||
return execute_command(name, add_pump_cmd(name, cs))
|
||||
|
||||
|
||||
def delete_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def delete_pump_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Pump(get_pump(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from pumps where id = {old.f_id};"
|
||||
@@ -111,7 +111,7 @@ def delete_pump_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_pump_cache(name, cs))
|
||||
return execute_command(name, delete_pump_cmd(name, cs))
|
||||
|
||||
|
||||
class InpPump:
|
||||
@@ -160,3 +160,33 @@ def inp_out_pump(name: str) -> list[str]:
|
||||
desc = ';'
|
||||
lines.append(f'{id} {node1} {node2} {power} {head} {speed} {pattern} {desc}')
|
||||
return lines
|
||||
|
||||
|
||||
'''def delete_pump_by_node(name: str, node: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from pumps where node1 = '{node}' or node2 = '{node}'")
|
||||
for row in rows:
|
||||
cs.append(g_delete_prefix | {'type': 'pump', 'id': row['id']})
|
||||
|
||||
return cs'''
|
||||
|
||||
|
||||
def unset_pump_by_curve(name: str, curve: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from pumps where head = '{curve}'")
|
||||
for row in rows:
|
||||
cs.append(g_update_prefix | {'type': 'pump', 'id': row['id'], 'head': None})
|
||||
|
||||
return cs
|
||||
|
||||
|
||||
def unset_pump_by_pattern(name: str, pattern: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from pumps where pattern = '{pattern}'")
|
||||
for row in rows:
|
||||
cs.append(g_update_prefix | {'type': 'pump', 'id': row['id'], 'pattern': None})
|
||||
|
||||
return cs
|
||||
|
||||
Reference in New Issue
Block a user