import sqlite3

def dump_database(db_file):
    connection = sqlite3.connect(db_file)
    cursor = connection.cursor()
    
    # Get the names of all tables in the database
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = cursor.fetchall()

    # Loop through each table
    for table in tables:
        table_name = table[0]
        print(f"\n-- Dumping data for table: {table_name} --")
        
        # Get the column names (keys)
        cursor.execute(f"PRAGMA table_info({table_name});")
        columns = cursor.fetchall()
        column_names = [column[1] for column in columns]
        print(f"Columns (Keys): {', '.join(column_names)}")
        
        # Get the data (values)
        cursor.execute(f"SELECT * FROM {table_name}")
        rows = cursor.fetchall()
        
        # Dump the key-value pairs (columns and their values)
        for row in rows:
            row_dict = dict(zip(column_names, row))
            print(row_dict)  # This prints the key-value pairs for each row

    connection.close()

# Example usage
dump_database("ledger.db")
