API Reference
SQLPyHelper
- class sqlpyhelper.db_helper.SQLPyHelper(db_type: str | None = None, host: str | None = None, user: str | None = None, password: str | None = None, database: str | None = None, driver: str | None = None, port: str | None = None, oracle_sid: str | None = None)[source]
Bases:
object- backup_table(table_name: str, backup_file: str) None[source]
Exports table data into a CSV file. Example: backup_table(‘users’, ‘users_backup.csv’)
- begin_transaction() None[source]
Begin an explicit transaction. Works across all supported databases.
- create_table(table_name: str, columns: dict[str, str]) None[source]
Creates a table dynamically using a dictionary format. Example: columns = {‘id’: ‘INTEGER PRIMARY KEY’, ‘name’: ‘TEXT’, ‘age’: ‘INTEGER’}
- execute_query(query: str, params: tuple | None = None) None[source]
Executes a query with optional parameters
- fetch_by_param(table_name: str, column_name: str, value: Any) list[tuple][source]
Fetches rows from a table where a column matches the given value.
- insert_bulk(table_name: str, data: list[dict[str, Any]]) None[source]
Inserts multiple rows at once. Example: data = [{‘id’: 1, ‘name’: ‘Alice’}, {‘id’: 2, ‘name’: ‘Bob’}]
- insert_dynamic(table: str, data: dict[str, Any]) None[source]
Dynamically constructs and executes an INSERT query with database-specific placeholders.
Exceptions
- class sqlpyhelper.db_helper.SQLPyHelperError[source]
Bases:
ExceptionBase exception for SQLPyHelper errors.
- class sqlpyhelper.db_helper.ConnectionError[source]
Bases:
SQLPyHelperErrorRaised when a database connection fails.
- class sqlpyhelper.db_helper.QueryError[source]
Bases:
SQLPyHelperErrorRaised when a query fails to execute.
- class sqlpyhelper.db_helper.BackupError[source]
Bases:
SQLPyHelperErrorRaised when a backup operation fails.