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 *
|
||||
|
||||
@@ -51,7 +51,7 @@ class Junction(object):
|
||||
return { 'type': self.type, 'id': self.id }
|
||||
|
||||
|
||||
def set_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def set_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Junction(get_junction(name, cs.operations[0]['id']))
|
||||
raw_new = get_junction(name, cs.operations[0]['id'])
|
||||
|
||||
@@ -75,10 +75,10 @@ def set_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_junction_cache(name, cs))
|
||||
return execute_command(name, set_junction_cmd(name, cs))
|
||||
|
||||
|
||||
def add_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def add_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
new = Junction(cs.operations[0])
|
||||
|
||||
redo_sql = f"insert into _node (id, type) values ({new.f_id}, {new.f_type});"
|
||||
@@ -96,10 +96,10 @@ def add_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, add_junction_cache(name, cs))
|
||||
return execute_command(name, add_junction_cmd(name, cs))
|
||||
|
||||
|
||||
def delete_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
def delete_junction_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
old = Junction(get_junction(name, cs.operations[0]['id']))
|
||||
|
||||
redo_sql = f"delete from coordinates where node = {old.f_id};"
|
||||
@@ -117,7 +117,7 @@ def delete_junction_cache(name: str, cs: ChangeSet) -> DbChangeSet:
|
||||
|
||||
|
||||
def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_junction_cache(name, cs))
|
||||
return execute_command(name, delete_junction_cmd(name, cs))
|
||||
|
||||
|
||||
class InpJunction:
|
||||
@@ -157,3 +157,13 @@ def inp_out_junction(name: str) -> list[str]:
|
||||
desc = ';'
|
||||
lines.append(f'{id} {elev} {demand} {pattern} {desc}')
|
||||
return lines
|
||||
|
||||
|
||||
def unset_junction_by_pattern(name: str, pattern: str) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
|
||||
rows = read_all(name, f"select id from junctions where pattern = '{pattern}'")
|
||||
for row in rows:
|
||||
cs.append(g_update_prefix | {'type': 'junction', 'id': row['id'], 'pattern': None})
|
||||
|
||||
return cs
|
||||
|
||||
Reference in New Issue
Block a user