Add more api for snapshot
This commit is contained in:
@@ -8,7 +8,12 @@ from .database import API_ADD, API_UPDATE, API_DELETE
|
||||
from .database import ChangeSet
|
||||
from .database import get_current_operation
|
||||
from .database import execute_undo, execute_redo
|
||||
from .database import have_snapshot, take_snapshot, pick_snapshot
|
||||
from .database import have_snapshot, have_snapshot_for_operation, have_snapshot_for_current_operation
|
||||
from .database import take_snapshot_for_operation, take_snapshot_for_current_operation, take_snapshot
|
||||
from .database import update_snapshot, update_snapshot_for_current_operation
|
||||
from .database import delete_snapshot, delete_snapshot_by_operation
|
||||
from .database import get_operation_by_snapshot, get_snapshot_by_operation
|
||||
from .database import pick_snapshot
|
||||
from .database import pick_operation, sync_with_server, get_restore_operation, set_restore_operation
|
||||
|
||||
from .batch_cmd import execute_batch_command
|
||||
|
||||
@@ -166,13 +166,55 @@ def have_snapshot(name: str, tag: str) -> bool:
|
||||
return read(name, f"select id from snapshot_operation where tag = '{tag}'") != None
|
||||
|
||||
|
||||
def take_snapshot(name: str, tag: str) -> int | None:
|
||||
def have_snapshot_for_operation(name: str, operation: int) -> bool:
|
||||
return read(name, f"select id from snapshot_operation where id = {operation}") != None
|
||||
|
||||
|
||||
def have_snapshot_for_current_operation(name: str) -> bool:
|
||||
return have_snapshot_for_operation(name, get_current_operation(name))
|
||||
|
||||
|
||||
def take_snapshot_for_operation(name: str, operation: int, tag: str) -> None:
|
||||
if tag == None or tag == '':
|
||||
return None
|
||||
write(name, f"insert into snapshot_operation (id, tag) values ({operation}, '{tag}')")
|
||||
|
||||
current = get_current_operation(name)
|
||||
write(name, f"insert into snapshot_operation (id, tag) values ({current}, '{tag}')")
|
||||
return current
|
||||
|
||||
def take_snapshot_for_current_operation(name: str, tag: str) -> int | None:
|
||||
take_snapshot_for_operation(name, get_current_operation(name), tag)
|
||||
|
||||
|
||||
# deprecated ! use take_snapshot_for_current_operation instead
|
||||
def take_snapshot(name: str, tag: str) -> int | None:
|
||||
take_snapshot_for_current_operation(name, tag)
|
||||
|
||||
|
||||
def update_snapshot(name: str, operation: int, tag: str) -> None:
|
||||
if tag == None or tag == '':
|
||||
return None
|
||||
write(name, f"update snapshot_operation set tag = '{tag}' where id = {operation}")
|
||||
|
||||
|
||||
def update_snapshot_for_current_operation(name: str, tag: str) -> None:
|
||||
return update_snapshot(name, get_current_operation(name), tag)
|
||||
|
||||
|
||||
def delete_snapshot(name: str, tag: str) -> None:
|
||||
write(name, f"delete from snapshot_operation where tag = '{tag}'")
|
||||
|
||||
|
||||
def delete_snapshot_by_operation(name: str, operation: int) -> None:
|
||||
write(name, f"delete from snapshot_operation where id = {operation}")
|
||||
|
||||
|
||||
def get_operation_by_snapshot(name: str, tag: str) -> int | None:
|
||||
row = try_read(name, f"select id from snapshot_operation where tag = '{tag}'")
|
||||
return int(row['id']) if row != None else None
|
||||
|
||||
|
||||
def get_snapshot_by_operation(name: str, operation: int) -> str | None:
|
||||
row = try_read(name, f"select tag from snapshot_operation where id = {operation}")
|
||||
return str(row['tag']) if row != None else None
|
||||
|
||||
|
||||
def _get_parents(name: str, id: int) -> list[int]:
|
||||
|
||||
31
tjnetwork.py
31
tjnetwork.py
@@ -176,9 +176,40 @@ def execute_redo(name: str) -> ChangeSet:
|
||||
def have_snapshot(name: str, tag: str) -> bool:
|
||||
return api.have_snapshot(name, tag)
|
||||
|
||||
def have_snapshot_for_operation(name: str, operation: int) -> bool:
|
||||
return api.have_snapshot_for_operation(name, operation)
|
||||
|
||||
def have_snapshot_for_current_operation(name: str) -> bool:
|
||||
return api.have_snapshot_for_current_operation(name)
|
||||
|
||||
def take_snapshot_for_operation(name: str, operation: int, tag: str) -> None:
|
||||
return api.take_snapshot_for_operation(name, operation, tag)
|
||||
|
||||
def take_snapshot_for_current_operation(name: str, tag: str) -> int | None:
|
||||
return api.take_snapshot_for_current_operation(name, tag)
|
||||
|
||||
# deprecated ! use take_snapshot_for_current_operation instead
|
||||
def take_snapshot(name: str, tag: str) -> int | None:
|
||||
return api.take_snapshot(name, tag)
|
||||
|
||||
def update_snapshot(name: str, operation: int, tag: str) -> None:
|
||||
return api.update_snapshot(name, operation, tag)
|
||||
|
||||
def update_snapshot_for_current_operation(name: str, tag: str) -> None:
|
||||
return api.update_snapshot_for_current_operation(name, tag)
|
||||
|
||||
def delete_snapshot(name: str, tag: str) -> None:
|
||||
return api.delete_snapshot(name, tag)
|
||||
|
||||
def delete_snapshot_by_operation(name: str, operation: int) -> None:
|
||||
return api.delete_snapshot_by_operation(name, operation)
|
||||
|
||||
def get_operation_by_snapshot(name: str, tag: str) -> int | None:
|
||||
return api.get_operation_by_snapshot(name, tag)
|
||||
|
||||
def get_snapshot_by_operation(name: str, operation: int) -> str | None:
|
||||
return api.get_snapshot_by_operation(name, operation)
|
||||
|
||||
def pick_snapshot(name: str, tag: str, discard: bool = False) -> ChangeSet:
|
||||
return api.pick_snapshot(name, tag, discard)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user