diff --git a/api/operation.py b/api/operation.py index 92c8d67..53d1f45 100644 --- a/api/operation.py +++ b/api/operation.py @@ -1,6 +1,14 @@ from psycopg.rows import dict_row from .connection import g_conn_dict as conn +def _get_parents(name: str, id: int) -> list[int]: + ids = [id] + with conn[name].cursor(row_factory=dict_row) as cur: + while ids[-1] != 0: + cur.execute(f"select parent from operation where id = {ids[-1]}") + ids.append(int(cur.fetchone()['parent'])) + return ids + def _get_current_operation(name: str) -> int: with conn[name].cursor(row_factory=dict_row) as cur: cur.execute(f"select id from current_operation") @@ -90,15 +98,6 @@ def take_snapshot(name: str, tag: str) -> None: parent = _get_current_operation(name) cur.execute(f"insert into snapshot_operation (id, tag) values ({curr}, '{tag}')") - -def _get_parents(name: str, id: int) -> list[int]: - ids = [id] - with conn[name].cursor(row_factory=dict_row) as cur: - while ids[-1] != 0: - cur.execute(f"select parent from operation where id = {ids[-1]}") - ids.append(int(cur.fetchone()['parent'])) - return ids - def pick_snapshot(name: str, tag: str) -> None: if tag == None or tag == '': print('Non empty tag is expected!')