Transaction Class

class Transaction(payment_db_path, db_key, 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

  • db_key (str) – key to unlock the encrypted sqlite database, unencrypted if sqlcipher3 not installed or unset

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

count()
Return type:

int

Returns:

count of the number of rows in the table, or 0 if no table

download_csv(session, url, merge=False)

Download the CSV from url and import into the sqlite database If a previous table exists, generate a diff

Parameters:
  • session (Session) – Requests session to use for download

  • url (str) – url of the csv to download

  • merge (bool) – (optional) If True, merge into existing table. Defaults to False.

get_row(entry_name, entry_value, only_one=True)

Retrieve a single or multiple rows matching column = value (case-insensitive)

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

  • entry_value (str) – Value to match

  • only_one (bool) – If True (default), return the first matching row If False, return a list of all matching rows

Return type:

Row | List[Row] | None

Returns:

  • If only_one=True → a single sqlite3.Row or None

  • If only_one=False → list of sqlite3.Row (may be empty)

get_row_multi(match_dict, only_one=True)

Retrieve one or many rows matching multiple column=value pairs

Parameters:
  • match_dict (dict) – Dictionary of column names and values to match

  • only_one (bool) – If True (default), return the first matching row If False, return a list of all matching rows

Return type:

Row | List[Row] | None

Returns:

  • If only_one=True → a single sqlite3.Row or None

  • If only_one=False → list of sqlite3.Row (may be empty)

import_csv(csv_path, merge=False)

Import the passed CSV into the encrypted sqlite database

Parameters:
  • csv_path (Path) – Path like path of csv file

  • merge (bool) – (optional) If True, merge into existing table. Defaults to False. Form importing current, and expired members as headings are the same.

print_diff(old_table)

Print out diff between old and new db

Parameters:

old_table (str) – The name the existing table was renamed to

rename_old_table(existing)

If there was an exising table rename for comparison

Parameters:

existing (bool) – bool for table exists

Return type:

str

Returns:

the old table name

run_count_query(sql, params)

Generate whole sql query for running on db table for counting and run

Parameters:
  • sql (str) – the sqlite query for matching rows

  • params (tuple) – the paramaters to use for the query

Return type:

int

Returns:

number of matching rows

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

table_exists()

Return True or False if a table exists

Return type:

bool