Skip to content

src.database.base_adapter.DatabaseAdapter

Bases: ABC

Abstract base class defining the interface for database operations.

This class serves as a template for implementing database adapters, ensuring consistent interface across different database backends. All database implementations must inherit from this class and implement its abstract methods.

Methods:

Name Description
add

Add data to the database

search

Search for data in the database

reset

Reset or clear the database

Example
class MyDatabaseClient(DatabaseAdapter):
    async def add(self, document, index_name):
        # Implementation for adding documents
        pass

    async def search(self, query, index_name):
        # Implementation for searching documents
        pass

    async def reset(self, index_name):
        # Implementation for resetting the database
        pass
Source code in src/database/base_adapter.py
 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
class DatabaseAdapter(ABC):
    """Abstract base class defining the interface for database operations.

    This class serves as a template for implementing database adapters,
    ensuring consistent interface across different database backends.
    All database implementations must inherit from this class and
    implement its abstract methods.

    Methods:
        add: Add data to the database
        search: Search for data in the database
        reset: Reset or clear the database

    Example:
        ```python
        class MyDatabaseClient(DatabaseAdapter):
            async def add(self, document, index_name):
                # Implementation for adding documents
                pass

            async def search(self, query, index_name):
                # Implementation for searching documents
                pass

            async def reset(self, index_name):
                # Implementation for resetting the database
                pass
        ```
    """

    @abstractmethod
    async def add(self, *args, **kwargs):
        """Add data to the database.

        This abstract method must be implemented by concrete database adapters
        to handle data insertion operations.

        Args:
            *args: Variable length argument list for flexibility across implementations
            **kwargs: Arbitrary keyword arguments for flexibility across implementations

        Raises:
            NotImplementedError: If the concrete class doesn't implement this method
        """
        pass

    @abstractmethod
    async def search(self, *args, **kwargs):
        """Search for data in the database.

        This abstract method must be implemented by concrete database adapters
        to handle search operations.

        Args:
            *args: Variable length argument list for flexibility across implementations
            **kwargs: Arbitrary keyword arguments for flexibility across implementations

        Raises:
            NotImplementedError: If the concrete class doesn't implement this method
        """
        pass

    @abstractmethod
    async def reset(self, *args, **kwargs):
        """Reset or clear data in the database.

        This abstract method must be implemented by concrete database adapters
        to handle database reset operations.

        Args:
            *args: Variable length argument list for flexibility across implementations
            **kwargs: Arbitrary keyword arguments for flexibility across implementations

        Raises:
            NotImplementedError: If the concrete class doesn't implement this method
        """
        pass

add(*args, **kwargs) abstractmethod async

Add data to the database.

This abstract method must be implemented by concrete database adapters to handle data insertion operations.

Parameters:

Name Type Description Default
*args

Variable length argument list for flexibility across implementations

()
**kwargs

Arbitrary keyword arguments for flexibility across implementations

{}

Raises:

Type Description
NotImplementedError

If the concrete class doesn't implement this method

Source code in src/database/base_adapter.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@abstractmethod
async def add(self, *args, **kwargs):
    """Add data to the database.

    This abstract method must be implemented by concrete database adapters
    to handle data insertion operations.

    Args:
        *args: Variable length argument list for flexibility across implementations
        **kwargs: Arbitrary keyword arguments for flexibility across implementations

    Raises:
        NotImplementedError: If the concrete class doesn't implement this method
    """
    pass

reset(*args, **kwargs) abstractmethod async

Reset or clear data in the database.

This abstract method must be implemented by concrete database adapters to handle database reset operations.

Parameters:

Name Type Description Default
*args

Variable length argument list for flexibility across implementations

()
**kwargs

Arbitrary keyword arguments for flexibility across implementations

{}

Raises:

Type Description
NotImplementedError

If the concrete class doesn't implement this method

Source code in src/database/base_adapter.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@abstractmethod
async def reset(self, *args, **kwargs):
    """Reset or clear data in the database.

    This abstract method must be implemented by concrete database adapters
    to handle database reset operations.

    Args:
        *args: Variable length argument list for flexibility across implementations
        **kwargs: Arbitrary keyword arguments for flexibility across implementations

    Raises:
        NotImplementedError: If the concrete class doesn't implement this method
    """
    pass

search(*args, **kwargs) abstractmethod async

Search for data in the database.

This abstract method must be implemented by concrete database adapters to handle search operations.

Parameters:

Name Type Description Default
*args

Variable length argument list for flexibility across implementations

()
**kwargs

Arbitrary keyword arguments for flexibility across implementations

{}

Raises:

Type Description
NotImplementedError

If the concrete class doesn't implement this method

Source code in src/database/base_adapter.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@abstractmethod
async def search(self, *args, **kwargs):
    """Search for data in the database.

    This abstract method must be implemented by concrete database adapters
    to handle search operations.

    Args:
        *args: Variable length argument list for flexibility across implementations
        **kwargs: Arbitrary keyword arguments for flexibility across implementations

    Raises:
        NotImplementedError: If the concrete class doesn't implement this method
    """
    pass