from typing import Any from ..core.database import ( ChangeSet, DatabaseCommand, execute_command, g_update_prefix, read, sql_literal, ) def get_backdrop_schema(name: str) -> dict[str, dict[str, Any]]: return { 'content' : {'type': 'str' , 'optional': False , 'readonly': False} } def get_backdrop(name: str) -> dict[str, Any]: e = read(name, "select content from gis.backdrops where id = true") return { 'content': e['content'] } def _set_backdrop(name: str, cs: ChangeSet) -> DatabaseCommand: statement = f"update gis.backdrops set content = {sql_literal(cs.operations[0]['content'])} where id = true;" change = g_update_prefix | { 'type': 'backdrop', 'content': cs.operations[0]['content'] } return DatabaseCommand(statement, [change]) def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet: return execute_command(name, _set_backdrop(name, cs)) def inp_in_backdrop(section: list[str]) -> str: if section == []: return str('') content = '\n'.join(section) return str(f"update gis.backdrops set content = {sql_literal(content)} where id = true;") def inp_out_backdrop(name: str) -> list[str]: obj = str(get_backdrop(name)['content']) return obj.split('\n')