-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInterface.py
49 lines (40 loc) · 1.7 KB
/
Interface.py
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
from abc import ABC, abstractmethod
from typing import Any, Dict
class DatabaseInterface(ABC):
"""
DatabaseInterface is an abstract base class that defines a common interface for CRUD operations on a database.
"""
@abstractmethod
def create(self, item: Dict[str, Any]) -> None:
"""
Create a new item in the database.
:param item: A dictionary representing the item to be created.
:raises NotImplementedError: This method must be overridden in a subclass.
"""
...
@abstractmethod
def read(self, key: Dict[str, Any]) -> Dict[str, Any]:
"""
Read an item from the database.
:param key: A dictionary representing the key of the item to be read.
:return: A dictionary representing the retrieved item, or an empty dictionary if the item is not found.
:raises NotImplementedError: This method must be overridden in a subclass.
"""
...
@abstractmethod
def update(self, key: Dict[str, Any], update_values: Dict[str, Any]) -> None:
"""
Update an existing item in the database.
:param key: A dictionary representing the key of the item to be updated.
:param update_values: A dictionary representing the attributes to be updated and their new values.
:raises NotImplementedError: This method must be overridden in a subclass.
"""
...
@abstractmethod
def delete(self, key: Dict[str, Any]) -> None:
"""
Delete an item from the database.
:param key: A dictionary representing the key of the item to be deleted.
:raises NotImplementedError: This method must be overridden in a subclass.
"""
...