From 23ce9d73d09e657f578b1e75671553754503555e Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Sun, 30 Oct 2022 14:43:22 +0800 Subject: [PATCH] Add batch change set for set demand --- api/operation.py | 7 +++++++ api/s9_demands.py | 14 +++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api/operation.py b/api/operation.py index 7fe031b..cf0293e 100644 --- a/api/operation.py +++ b/api/operation.py @@ -49,6 +49,13 @@ class SqlChangeSet: self.redo_cs = redo_cs self.undo_cs = undo_cs +class BatchSqlChangeSet: + def __init__(self, redo_sql: str, undo_sql: str, redo_cs: list[dict[str, str]], undo_cs: list[dict[str, str]]) -> None: + self.redo_sql = redo_sql + self.undo_sql = undo_sql + self.redo_cs = redo_cs + self.undo_cs = undo_cs + def read(name: str, sql: str) -> Row: with conn[name].cursor(row_factory=dict_row) as cur: diff --git a/api/s9_demands.py b/api/s9_demands.py index 90cd815..399e77d 100644 --- a/api/s9_demands.py +++ b/api/s9_demands.py @@ -21,15 +21,7 @@ def get_demand(name: str, junction: str) -> dict[str, Any]: return { 'junction': junction, 'demands': ds } -class _SqlChangeSet: - def __init__(self, redo_sql: str, undo_sql: str, redo_cs: list[dict[str, str]], undo_cs: list[dict[str, str]]) -> None: - self.redo_sql = redo_sql - self.undo_sql = undo_sql - self.redo_cs = redo_cs - self.undo_cs = undo_cs - - -def set_demand_cache(name: str, cs: ChangeSet) -> _SqlChangeSet: +def set_demand_cache(name: str, cs: ChangeSet) -> BatchSqlChangeSet: junction = cs.operations[0]['junction'] old = get_demand(name, junction) new = { 'junction': junction, 'demands': [] } @@ -82,11 +74,11 @@ def set_demand_cache(name: str, cs: ChangeSet) -> _SqlChangeSet: undo_sql += _undo_sql redo_cs.append(cache.redo_cs) - + undo_cs.append(cache.undo_cs) undo_cs.reverse() - return _SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs) + return BatchSqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs) def set_demand(name: str, cs: ChangeSet) -> ChangeSet: