Transaction Class¶
- class Transaction(payment_db_path, db_key, table_name='completed_payments')¶
Bases:
MojoSkelHandles importing and querying completed payment data
- Extends:
MojoSkel: Base class with transaction database operations
- Parameters:
payment_db_path (
str) – Path to the SQLite databasedb_key (
str) – key to unlock the encrypted sqlite database, unencrypted if sqlcipher3 not installed or unsettable_name (
str) – (optional) Name of the table. Defaults to “completed_payments”
- count()¶
- Return type:
int- Returns:
count of the number of rows in the table, or 0 if no table
- create_joined_table(table_name, join_table, join_col='payment_id', is_view=True)¶
Create a View or Table that joins the current table with another table
- Parameters:
table_name (
str) – Name of the view or table to createjoin_table (
str) – Name of the table to join withjoin_col (
str) – (optional) Column name to join on. Defaults to “payment_id”is_view (
bool) – (optional) If True, create a VIEW, otherwise a TABLE. Defaults to True.
- create_view(view_name, join_table, join_col='payment_id')¶
Create a View that joins the current table with another table
- download_csv(session, url, merge=False, table_name=None)¶
Download CSV and relink items
- get_row(entry_name, entry_value, only_one=True, table_name=None)¶
Retrieve a single or multiple rows matching column = value (case-insensitive)
- Parameters:
entry_name (
str) – Column name to filter byentry_value (
str) – Value to matchonly_one (
bool) – If True (default), return the first matching row If False, return a list of all matching rowstable_name (
str) – (optional) Table name to use for query. Defaults to self.table_name.
- 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, table_name=None)¶
Retrieve one or many rows matching multiple column=value pairs
- Parameters:
match_dict (
dict) – Dictionary of column names and values to matchonly_one (
bool) – If True (default), return the first matching row If False, return a list of all matching rowstable_name (
str) – (optional) Table name to use for query. Defaults to self.table_name.
- 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, table_name=None)¶
Import CSV and relink items
- link_items(table_name='linked_payments', force=False)¶
Link completed_payments with payment_items through a SQL table
- Parameters:
table_name (
str) – (optional) Name of the table. Defaults to “linked_payments”force (
bool) – (optional) If True, recreate the table even if it exists.
- 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 rowsparams (
tuple) – the paramaters to use for the query
- Return type:
int- Returns:
number of matching rows
- set_table(table_name)¶
Switch to a different table and update the row_class
- 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