Support cascade deletion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from .operation import *
|
||||
from .database import *
|
||||
from .s0_base import *
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class Pipe(object):
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
|
||||
|
||||
def set_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Pipe(get_pipe(name, cs.operations[0]['id']))
|
||||
raw_new = get_pipe(name, cs.operations[0]['id'])
|
||||
|
||||
@@ -82,10 +82,10 @@ def set_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_pipe_cache(name, cs))
|
||||
return execute_command(name, set_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
def add_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Pipe(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into _link (id, type) values ({new.f_id}, {new.f_type});"
|
||||
@@ -101,10 +101,10 @@ def add_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_pipe_cache(name, cs))
|
||||
return execute_command(name, add_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
def delete_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def delete_pipe_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Pipe(get_pipe(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from pipes where id = {old.f_id};"
|
||||
@@ -120,7 +120,7 @@ def delete_pipe_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_pipe_cache(name, cs))
|
||||
return execute_command(name, delete_pipe_cmd(name, cs))
|
||||
|
||||
|
||||
class InpPipe:
|
||||
@@ -169,3 +169,13 @@ def inp_out_pipe(name: str) -> list[str]:
|
||||
desc = ';'
|
||||
lines.append(f'{id} {node1} {node2} {length} {diameter} {roughness} {minor_loss} {status} {desc}')
|
||||
return lines
|
||||
|
||||
|
||||
'''def delete_pipe_by_node(name: str, node: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from pipes where node1 = '{node}' or node2 = '{node}'")
|
||||
for row in rows:
|
||||
cs.append(g_delete_prefix | {'type': 'pipe', 'id': row['id']})
|
||||
|
||||
return cs'''
|
||||
|
||||
Reference in New Issue
Block a user