-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathdatabase_base.py
More file actions
115 lines (91 loc) · 3.56 KB
/
database_base.py
File metadata and controls
115 lines (91 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""DatabaseBase class for managing database operations"""
import uuid
from abc import ABC, abstractmethod
from typing import Dict, List, Optional
from common.models.api import BatchRecord, FileRecord, LogType
from semantic_kernel.contents import AuthorRole
from sql_agents.helpers.models import AgentType
class DatabaseBase(ABC):
"""Abstract base class for database operations."""
@abstractmethod
async def initialize_cosmos(self) -> None:
"""Initialize the cosmosdb client and create container if needed"""
pass # pragma: no cover
@abstractmethod
async def create_batch(self, user_id: str, batch_id: uuid.UUID) -> BatchRecord:
"""Create a new conversion batch"""
pass # pragma: no cover
@abstractmethod
async def get_file_logs(self, file_id: str) -> Dict:
"""Retrieve all logs for a file"""
pass # pragma: no cover
@abstractmethod
async def get_batch_from_id(self, batch_id: str) -> Dict:
"""Retrieve all logs for a file"""
pass # pragma: no cover
@abstractmethod
async def get_batch_files(self, batch_id: str) -> List[Dict]:
"""Retrieve all files for a batch"""
pass # pragma: no cover
@abstractmethod
async def delete_file_logs(self, file_id: str) -> None:
"""Delete all logs for a file"""
pass # pragma: no cover
@abstractmethod
async def get_user_batches(self, user_id: str) -> Dict:
"""Retrieve all batches for a user"""
pass # pragma: no cover
@abstractmethod
async def add_file(
self, batch_id: uuid.UUID, file_id: uuid.UUID, file_name: str, storage_path: str
) -> FileRecord:
"""Add a file entry to the database"""
pass # pragma: no cover
@abstractmethod
async def get_batch(self, user_id: str, batch_id: str) -> Optional[Dict]:
"""Retrieve a batch and its associated files"""
pass # pragma: no cover
@abstractmethod
async def get_file(self, file_id: str) -> Optional[Dict]:
"""Retrieve a file entry along with its logs"""
pass # pragma: no cover
@abstractmethod
async def add_file_log(
self,
file_id: str,
description: str,
last_candidate: str,
log_type: LogType,
agent_type: AgentType,
author_role: AuthorRole,
) -> None:
"""Log a file status update"""
pass # pragma: no cover
@abstractmethod
async def update_file(self, file_record: FileRecord) -> None:
"""Update file record"""
pass # pragma: no cover
@abstractmethod
async def update_batch(self, batch_record: BatchRecord) -> BatchRecord:
"""Update a batch record"""
pass # pragma: no cover
@abstractmethod
async def delete_all(self, user_id: str) -> None:
"""Delete all batches, files, and logs for a user"""
pass # pragma: no cover
@abstractmethod
async def delete_batch(self, user_id: str, batch_id: str) -> None:
"""Delete a batch along with its files and logs"""
pass # pragma: no cover
@abstractmethod
async def delete_file(self, user_id: str, batch_id: str, file_id: str) -> None:
"""Delete a file and its logs, and update batch file count"""
pass # pragma: no cover
@abstractmethod
async def get_batch_history(self, user_id: str, batch_id: str) -> List[Dict]:
"""Retrieve all logs for a batch"""
pass # pragma: no cover
@abstractmethod
async def close(self) -> None:
"""Close database connection"""
pass # pragma: no cover