DbUnify.SQLite3.sync.Raw package

Submodules

DbUnify.SQLite3.sync.Raw.Raw module

class DbUnify.SQLite3.sync.Raw.Raw.Raw(manager)[source]

Bases: object

# Raw Class

#### The Raw class provides methods for executing raw SQL queries, creating database backups, restoring backups, #### listing tables, inserting and reading base64 encoded data.

### Attributes:
  • manager (Manager): The Manager instance managing the database connection.

### Methods:
  • __init__(self, manager): Initializes the Raw instance with a Manager instance.

  • backup_database(self, backup_path): Creates a backup of the database.

  • restore_database(self, backup_path): Restores the database from a backup.

  • execute_query(self, query, *args): Executes a database query.

  • list_tables(self): Gets a list of all tables in the SQLite database.

  • insert_base64(self, table_name, data_dict): Inserts base64 encoded data into a database table.

  • read_base64(self, table_name, only_base64): Reads and decodes base64 encoded data from a database table.

### Raises:
  • RuntimeError: If there is an error during database backup, restoration, query execution, listing tables, or reading and decoding base64 data.

### Note:
  • This class is designed for asynchronous usage and requires the use of the ‘async’ and ‘await’ keywords for method calls.

  • The ‘Manager’ class is used internally for managing the database connection.

backup_database(backup_path: str) bool[source]

Create a backup of the database.

Parameters:

backup_path (str) – The path where the backup should be stored.

Returns:

True if the backup was successful, False otherwise.

Return type:

bool

Raises:

RuntimeError – If there is an error creating the database backup.

execute_query(query: str, *args: Any) bool[source]

Execute a database query.

Parameters:
  • query (str) – The SQL query to be executed.

  • *args – Parameters to be passed to the query.

Returns:

True if the query was successful, False otherwise.

Return type:

bool

Raises:

RuntimeError – If there is an error executing the query.

insert_base64(table_name: str, data_dict: Dict[str, Any]) None[source]

Insert base64 encoded data into a database table.

Parameters:
  • table_name (str) – Name of the table to insert data into.

  • data_dict (dict) – A dictionary where keys are column names, and values are data to be encoded and inserted.

Raises:

RuntimeError – If there is an error inserting the data.

list_tables() List[str][source]

Get a list of all tables in the SQLite database.

Returns:

A list of table names.

Return type:

list

Raises:

RuntimeError – If there is an error listing tables.

read_base64(table_name: str, only_base64: bool) List[Dict[str, Any]][source]

Read and decode base64 encoded data from a database table.

Parameters:
  • table_name (str) – Name of the table to read data from.

  • only_base64 (bool) – If True, only return rows where at least one column contains base64 encoded data.

Returns:

A list of dictionaries where keys are column names, and values are decoded data as bytes.

Return type:

list

Raises:

RuntimeError – If there is an error selecting or decoding the data.

restore_database(backup_path: str) bool[source]

Restore the database from a backup.

Parameters:

backup_path (str) – The path to the backup file.

Returns:

True if the restore was successful, False otherwise.

Return type:

bool

Raises:

RuntimeError – If there is an error restoring the database.

Module contents