Accept Merge Request #171: (list-snapshot -> master)

Merge Request: Support to list snapshot

Created By: @王琼钰
Accepted By: @王琼钰
URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/171?initial=true
This commit is contained in:
王琼钰
2023-03-03 20:40:38 +08:00
3 changed files with 12 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ 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 list_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

View File

@@ -162,6 +162,14 @@ def execute_redo(name: str) -> ChangeSet:
return ChangeSet.from_list(e)
def list_snapshot(name: str) -> list[tuple[int, str]]:
rows = read_all(name, f'select * from operation order by id')
result = []
for row in rows:
result.append((int(row['id']), str(row['tag'])))
return result
def have_snapshot(name: str, tag: str) -> bool:
return try_read(name, f"select id from snapshot_operation where tag = '{tag}'") != None

View File

@@ -173,6 +173,9 @@ def execute_undo(name: str, discard: bool = False) -> ChangeSet:
def execute_redo(name: str) -> ChangeSet:
return api.execute_redo(name)
def list_snapshot(name: str) -> list[tuple[int, str]]:
return api.list_snapshot(name)
def have_snapshot(name: str, tag: str) -> bool:
return api.have_snapshot(name, tag)