Support cascade deletion

This commit is contained in:
WQY\qiong
2023-02-04 13:45:14 +08:00
parent 633a616d39
commit 804e1c7796
38 changed files with 1272 additions and 707 deletions

View File

@@ -1,4 +1,4 @@
from .operation import *
from .database import *
from .s0_base import *
SOURCE_TYPE_CONCEN = 'CONCEN'
@@ -44,7 +44,7 @@ class Source(object):
return { 'type': self.type, 'node': self.node }
def set_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def set_source_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
old = Source(get_source(name, cs.operations[0]['node']))
raw_new = get_source(name, cs.operations[0]['node'])
@@ -65,10 +65,10 @@ def set_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def set_source(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_source_cache(name, cs))
return execute_command(name, set_source_cmd(name, cs))
def add_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def add_source_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
new = Source(cs.operations[0])
redo_sql = f"insert into sources (node, type, strength, pattern) values ({new.f_node}, {new.f_s_type}, {new.f_strength}, {new.f_pattern});"
@@ -81,10 +81,10 @@ def add_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def add_source(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, add_source_cache(name, cs))
return execute_command(name, add_source_cmd(name, cs))
def delete_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def delete_source_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
old = Source(get_source(name, cs.operations[0]['node']))
redo_sql = f"delete from sources where node = {old.f_node};"
@@ -97,7 +97,7 @@ def delete_source_cache(name: str, cs: ChangeSet) -> DbChangeSet:
def delete_source(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, delete_source_cache(name, cs))
return execute_command(name, delete_source_cmd(name, cs))
class InpSource:
@@ -135,3 +135,20 @@ def inp_out_source(name: str) -> list[str]:
pattern = obj['pattern'] if obj['pattern'] != None else ''
lines.append(f'{node} {s_type} {strength} {pattern}')
return lines
def delete_source_by_node(name: str, node: str) -> ChangeSet:
row = try_read(name, f"select * from sources where node = '{node}'")
if row == None:
return ChangeSet()
return ChangeSet(g_delete_prefix | {'type' : 'source', 'node': node})
def unset_source_by_pattern(name: str, pattern: str) -> ChangeSet:
cs = ChangeSet()
rows = read_all(name, f"select node from sources where pattern = '{pattern}'")
for row in rows:
cs.append(g_update_prefix | {'type': 'source', 'node': row['node'], 'pattern': None})
return cs