actio_python_utils.database_functions

Database-related functionality.

Functions

connect_to_db([service, db_args])

Return a connection to the specified PostgreSQL database

get_db_args([service, db_args, logger, ...])

Returns a dict of arguments to log in with psycopg2.

get_pg_config([service, service_fn, pgpass_fn])

Locates the PostgreSQL login credentials given a service name.

replace_dict_values_with_global_definition(mapping)

Replaces values in the mapping with those in global_mapping when the value is a str and it is a key in the global mapping

savepoint(cur[, savepoint])

Creates a context manager to create a savepoint upon entering, rollback if an error occurs, and release upon exiting

savepoint_wrapper(method)

Wraps a psycopg2 cursor's method to use a savepoint

split_schema_from_table(table[, default_schema])

Split a possibly schema qualified table name into its schema and table names

Classes

DBConnection([service, db_args, log_name, ...])

Creates a psycopg2 database connection with the specified parameters and acts as a context manager.

LoggingCursor(*args[, log_level, log_name])

Wraps psycopg2.extras.DictCursor such that each copy_expert and execute statement is logged

SavepointCursor(*args[, log_level, log_name])

Wraps LoggingCursor methods to use a savepoint context manager