Database management

Classes and functions for managing access to the databases

source

get_db_credentials

 get_db_credentials ()

*Fetch PostgreSQL database credentials from the configuration file of the kedro project.

Uses OmegaConfigLoader to load credentials stored under credentials.postgres.

Returns: dict: A dictionary with the database connection details (e.g., host, port, user, password, dbname).*


source

insert_multi_rows

 insert_multi_rows (data_to_insert:pandas.core.frame.DataFrame,
                    table_name:str, column_names:list, types:list, cur,
                    conn, return_with_ids:bool=False,
                    unique_columns:list=None)

*Inserts data into the specified database table, with an optional return of database-assigned IDs.

Args: data_to_insert (pd.DataFrame): DataFrame containing the data to be inserted. table_name (str): Name of the target database table. column_names (list): List of column names for the target table. types (list): List of Python types (e.g., [int, float]) for data conversion. cur (psycopg2.cursor): Database cursor for executing SQL commands. conn (psycopg2.connection): Database connection for committing transactions. return_with_ids (bool): If True, returns the original DataFrame with an additional “ID” column.

Returns: pd.DataFrame | None: Original DataFrame with an “ID” column if return_with_ids is True; otherwise, None.*

Type Default Details
data_to_insert DataFrame
table_name str
column_names list
types list
cur
conn
return_with_ids bool False
unique_columns list None mandatory if return_with_ids is True
Returns pandas.core.frame.DataFrame | None