Transaction Class

class Transaction(payment_db_path, table_name='payments')

Bases: MojoSkel

Handles importing and querying completed payment data.

Extends:

MojoSkel: Base class with transaction database operations.

Parameters:
  • payment_db_path (str) – Path to the SQLite database.

  • table_name (str) – (optional) Name of the table. Defaults to “payments”.

count()

Returns count of the number of rows in the table.

Return type:

int

get_row(entry_name, entry_value)

Retrieve a single row matching column = value (case-insensitive).

Parameters:
  • entry_name (str) – Column name to filter by.

  • entry_value (str) – Value to match.

Return type:

dict

Returns:

The matching row as a dictionary, or None if not found.

get_row_multi(match_dict)

Retrieve the first row matching multiple column = value pairs.

Parameters:

match_dict (dict) – Dictionary of column names and values to match.

Return type:

dict

Returns:

The first matching row, or None if not found.

import_csv(csv_path, pk_column=None, sample_size=100)

Import a completed_payments.csv file into SQLite.

Infers column types and logs failed rows. Creates the table if needed.

Parameters:
  • csv_path (Path) – Path to the CSV file.

  • pk_column (str) – (optional) Primary key column name. Defaults to the first column.

  • sample_size (int) – (optional) Number of rows to sample for type inference. Defaults to 100.

Raises:

ValueError – If the CSV is empty or contains failed insertions.

show_table(limit=2)

Print the first few rows of the table as dictionaries.

Parameters:

limit (int) – (optional) Number of rows to display. Defaults to 2.