Skip to content

Dbclient

flowtask.components.DbClient

DbClient

DbClient(*args, **kwargs)

Bases: DBInterface

DbClient.

Abstract base class for database clients using AsyncDB.

Provides common methods for connecting to a database, executing queries, and handling results.

Inherits from the DBInterface interface.

.. note:: This class is intended to be subclassed by specific database client implementations.

.. table:: Properties :widths: auto

+--------------------+----------+--------------------------------------------------------------------------------+ | Name | Required | Description | +--------------------+----------+--------------------------------------------------------------------------------+ | driver | Yes | Database driver to use (e.g., "pg" for PostgreSQL). | +--------------------+----------+--------------------------------------------------------------------------------+ | credentials | Yes | Dictionary containing database connection credentials (user, password, etc.). | | | | Defined by the _credentials class attribute. | +--------------------+----------+--------------------------------------------------------------------------------+ | raw_result | No | Boolean flag indicating whether to return raw query results or convert them | | | | to dictionaries (defaults to False). | +--------------------+----------+--------------------------------------------------------------------------------+ | infer_types | No | Boolean flag indicating whether to infer data types for pandas DataFrames | | | | created from query results (defaults to False). | +--------------------+----------+--------------------------------------------------------------------------------+ | as_dataframe | No | Boolean flag indicating whether to convert query results to a pandas DataFrame | | | | (defaults to True). | +--------------------+----------+--------------------------------------------------------------------------------+ | as_string | No | Boolean flag indicating whether to convert object columns in DataFrames | | | | to strings (defaults to False). Converting to strings requires type | | | | inference (set infer_types to True if used). | +--------------------+----------+--------------------------------------------------------------------------------+

.. returns:: varies The return value of the _query method depends on the raw_result and as_dataframe properties: * If raw_result is True: Returns the raw result object specific to the database driver. * If raw_result is False and as_dataframe is True: Returns a pandas DataFrame containing the query results. * If raw_result is False and as_dataframe is False: Returns a list of dictionaries representing the query results. Raises exceptions for errors during execution (e.g., DataNotFound, ComponentError).