Skip to content

BaseClient

BaseClient

BaseClient(table_name: str)

Bases: ABC

Abstract base class for all client implementations.

This class defines the interface that all concrete client classes must implement. It provides a common execute method for dispatching queries based on the QueryBuilder's mode and defines abstract methods for the core database operations.

Subclasses must implement the abstract methods to provide concrete implementations for interacting with a specific database or service.

The table name is used to identify the target table for database operations.

Parameters:

Name Type Description Default
table_name str

The name of the table to operate on.

required

Methods:

Name Description
execute

Executes a query constructed by the provided QueryBuilder.

Source code in supadantic/clients/base.py
31
32
33
34
35
36
37
38
39
40
41
def __init__(self, table_name: str) -> None:
    """
    Initializes the client with the table name.

    The table name is used to identify the target table for database operations.

    Args:
        table_name (str): The name of the table to operate on.
    """

    self.table_name = table_name

execute

execute(*, query_builder: QueryBuilder) -> list[dict[str, Any]] | int

Executes a query constructed by the provided QueryBuilder.

This method acts as a dispatcher, selecting the appropriate database operation based on the query_builder.mode.

Parameters:

Name Type Description Default
query_builder QueryBuilder

The QueryBuilder instance containing the query details and execution mode. The mode determines which underlying database operation will be performed.

required

Returns:

Type Description
dict[str, Any] | int

A dictionary containing the results of the query for insert, update, or filter operations; or an integer representing the number of affected rows for delete or count operations. The exact structure of the dictionary depends on the specific data returned by the underlying database.

Source code in supadantic/clients/base.py
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
def execute(self, *, query_builder: QueryBuilder) -> list[dict[str, Any]] | int:
    """
    Executes a query constructed by the provided QueryBuilder.

    This method acts as a dispatcher, selecting the appropriate database operation
    based on the `query_builder.mode`.

    Args:
        query_builder (QueryBuilder): The QueryBuilder instance containing the query details
                       and execution mode.  The mode determines which underlying
                       database operation will be performed.

    Returns:
        (dict[str, Any] | int): A dictionary containing the results of the query for insert,
                                update, or filter operations; or an integer representing the number
                                of affected rows for delete or count operations. The exact structure
                                of the dictionary depends on the specific data returned by the underlying database.
    """

    map_modes: dict[QueryBuilder.Mode, Callable] = {
        QueryBuilder.Mode.DELETE_MODE: self._delete,
        QueryBuilder.Mode.INSERT_MODE: self._insert,
        QueryBuilder.Mode.UPDATE_MODE: self._update,
        QueryBuilder.Mode.FILTER_MODE: self._filter,
        QueryBuilder.Mode.COUNT_MODE: self._count,
    }

    return map_modes[query_builder.mode](query_builder=query_builder)