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.
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from typing import Any
|
|
|
|
from ..core.database import (
|
|
ChangeSet,
|
|
DatabaseCommand,
|
|
execute_command,
|
|
g_update_prefix,
|
|
read_all,
|
|
sql_literal,
|
|
)
|
|
|
|
|
|
def get_title_schema(name: str) -> dict[str, dict[str, Any]]:
|
|
return {"value": {"type": "str", "optional": False, "readonly": False}}
|
|
|
|
|
|
def get_title(name: str) -> dict[str, Any]:
|
|
rows = read_all(
|
|
name,
|
|
"select value from network.model_titles order by sequence_no",
|
|
)
|
|
return {"value": "\n".join(str(row["value"]) for row in rows)}
|
|
|
|
|
|
def _replace_title_sql(value: str) -> str:
|
|
statements = ["delete from network.model_titles;"]
|
|
for sequence_no, line in enumerate(value.split("\n")):
|
|
statements.append(
|
|
"insert into network.model_titles (sequence_no, value) "
|
|
f"values ({sequence_no}, {sql_literal(line)});"
|
|
)
|
|
return "\n".join(statements)
|
|
|
|
|
|
def _set_title(name: str, cs: ChangeSet) -> DatabaseCommand:
|
|
new = str(cs.operations[0]["value"])
|
|
return DatabaseCommand(
|
|
_replace_title_sql(new),
|
|
[g_update_prefix | {"type": "title", "value": new}],
|
|
)
|
|
|
|
|
|
def set_title(name: str, cs: ChangeSet) -> ChangeSet:
|
|
return execute_command(name, _set_title(name, cs))
|
|
|
|
|
|
def inp_in_title(section: list[str]) -> str:
|
|
return _replace_title_sql("\n".join(section))
|
|
|
|
|
|
def inp_out_title(name: str) -> list[str]:
|
|
return str(get_title(name)["value"]).split("\n")
|