52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from .database import *
|
|
|
|
|
|
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, f"select * from backdrop")
|
|
return { 'content': e['content'] }
|
|
|
|
|
|
def set_backdrop_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
|
|
old = get_backdrop(name)
|
|
|
|
redo_sql = f"update backdrop set content = '{cs.operations[0]['content']}' where content = '{old['content']}';"
|
|
undo_sql = f"update backdrop set content = '{old['content']}' where content = '{cs.operations[0]['content']}';"
|
|
|
|
redo_cs = g_update_prefix | { 'type': 'backdrop', 'content': cs.operations[0]['content'] }
|
|
undo_cs = g_update_prefix | { 'type': 'backdrop', 'content': old['content'] }
|
|
|
|
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
|
|
|
|
|
|
def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet:
|
|
return execute_command(name, set_backdrop_cmd(name, cs))
|
|
|
|
|
|
class InpBackdrop:
|
|
def __init__(self, section) -> None:
|
|
self.value = '\n'.join(section)
|
|
|
|
|
|
def inp_in_backdrop(section: list[str]) -> ChangeSet:
|
|
if len(section) > 0:
|
|
obj = InpBackdrop(section)
|
|
return ChangeSet(g_update_prefix | {'type': 'backdrop', 'content' : obj.value})
|
|
return ChangeSet()
|
|
|
|
|
|
def inp_in_backdrop_new(name: str, section: list[str]) -> None:
|
|
if section == []:
|
|
return
|
|
|
|
content = '\n'.join(section)
|
|
sql = f"update backdrop set content = '{content}';"
|
|
write(name, sql)
|
|
|
|
|
|
def inp_out_backdrop(name: str) -> list[str]:
|
|
obj = str(get_backdrop(name)['content'])
|
|
return obj.split('\n') |