refactor(db)!: adopt project-routed pooled databases
Reorganize WNDB by responsibility and remove legacy scheme endpoints.\n\nRoute analysis and time-series access through project pools, preserve transactional realtime replacement, and refresh GIS materialized views after writes.\n\nAdd database architecture documentation, live pooling coverage, API contract updates, and executable container verification.\n\nBREAKING CHANGE: legacy scheme APIs and flat app.native.wndb module imports are removed.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from typing import Any
|
||||
|
||||
from ..core.database import (
|
||||
ChangeSet,
|
||||
DatabaseCommand,
|
||||
execute_command,
|
||||
g_update_prefix,
|
||||
read_all,
|
||||
sql_literal,
|
||||
)
|
||||
|
||||
|
||||
def get_rule_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return { 'rules' : {'type': 'str_list' , 'optional': False , 'readonly': False} }
|
||||
|
||||
|
||||
def get_rule(name: str) -> dict[str, Any]:
|
||||
cs = read_all(name, "select line from network.rules order by sequence_no")
|
||||
ds = []
|
||||
for c in cs:
|
||||
ds.append(c['line'])
|
||||
return { 'rules': ds }
|
||||
|
||||
|
||||
def _set_rule(name: str, cs: ChangeSet) -> DatabaseCommand:
|
||||
statement = 'delete from network.rules;'
|
||||
for sequence_no, line in enumerate(cs.operations[0]['rules']):
|
||||
statement += f"\ninsert into network.rules (sequence_no, line) values ({sequence_no}, {sql_literal(line)});"
|
||||
|
||||
change = g_update_prefix | { 'type': 'rule', 'rules': cs.operations[0]['rules'] }
|
||||
|
||||
return DatabaseCommand(statement, [change])
|
||||
|
||||
|
||||
def set_rule(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, _set_rule(name, cs))
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# [EPA2][EPA3]
|
||||
# TODO...
|
||||
#--------------------------------------------------------------
|
||||
|
||||
|
||||
def inp_in_rule(line: str) -> str:
|
||||
return str(f"insert into network.rules (sequence_no, line) values ((select coalesce(max(sequence_no) + 1, 0) from network.rules), {sql_literal(line)});")
|
||||
|
||||
|
||||
def inp_out_rule(name: str) -> list[str]:
|
||||
return get_rule(name)['rules']
|
||||
Reference in New Issue
Block a user