pain001.db package#

Submodules#

pain001.db.load_db_data module#

pain001.db.load_db_data.load_db_data(data_file_path: str, table_name: str) list[dict[str, Any]][source]#

Load data from an SQLite database table into a list of dictionaries.

Parameters:
  • data_file_path (str) – The path to the SQLite database file.

  • table_name (str) – The name of the table from which data will be loaded.

Returns:

A list of dictionaries where each dictionary represents a row of data. The keys in each dictionary correspond to the column names, and the values are the column values for that row.

Return type:

list

Raises:
  • FileNotFoundError – If the SQLite file specified by data_file_path does not exist.

  • sqlite3.OperationalError – If there is an issue with SQLite database operations.

Example

data = load_db_data(“my_database.db”, “my_table”)

pain001.db.load_db_data.sanitize_table_name(table_name: str) str[source]#

Validate and sanitize a table name to prevent SQL injection. Uses strict validation: only alphanumeric characters and underscores allowed. MUST start with a letter (SQL identifier rules).

Parameters:

table_name (str) – The table name to validate.

Returns:

The validated table name (unchanged if valid).

Return type:

str

Raises:

ConfigurationError – If the table name is empty or contains invalid characters.

pain001.db.validate_db_data module#

pain001.db.validate_db_data.validate_db_data(data: list[dict[str, Any]]) bool[source]#

Validate the data from a database.

Parameters:

data (list of dict) – The data to validate.

Returns:

True if the data is valid, False otherwise.

Return type:

bool

Module contents#

Database operations module for pain001.