pystratum_mysql package¶
Subpackages¶
- pystratum_mysql.backend package
- pystratum_mysql.helper package
- pystratum_mysql.wrapper package
- Submodules
- pystratum_mysql.wrapper.MySqlBulkWrapper module
- pystratum_mysql.wrapper.MySqlFunctionsWrapper module
- pystratum_mysql.wrapper.MySqlLogWrapper module
- pystratum_mysql.wrapper.MySqlMultiWrapper module
- pystratum_mysql.wrapper.MySqlNoneWrapper module
- pystratum_mysql.wrapper.MySqlRow0Wrapper module
- pystratum_mysql.wrapper.MySqlRow1Wrapper module
- pystratum_mysql.wrapper.MySqlRowsWithIndexWrapper module
- pystratum_mysql.wrapper.MySqlRowsWithKeyWrapper module
- pystratum_mysql.wrapper.MySqlRowsWrapper module
- pystratum_mysql.wrapper.MySqlSingleton0Wrapper module
- pystratum_mysql.wrapper.MySqlSingleton1Wrapper module
- pystratum_mysql.wrapper.MySqlTableWrapper module
- pystratum_mysql.wrapper.MySqlWrapper module
- Module contents
Submodules¶
pystratum_mysql.MySqlConnector module¶
pystratum_mysql.MySqlDataLayer module¶
-
class
pystratum_mysql.MySqlDataLayer.
MySqlDataLayer
(connector: pystratum_mysql.MySqlConnector.MySqlConnector)[source]¶ Bases:
object
Class for connecting to a MySQL instance and executing SQL statements. Also, a parent class for classes with static wrapper methods for executing stored procedures and functions.
-
commit
() → None[source]¶ Commits the current transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html
-
connect
() → None[source]¶ Connects to a MySQL instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html for a complete overview of all possible keys in config.
-
connect_if_not_alive
() → None[source]¶ Connects or reconnects to the MySQL or MariaDB instance when Python is not (longer) connected to a MySQL or MariaDB instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html for a complete overview of all possible keys in config.
-
disconnect
() → None[source]¶ Disconnects from the MySQL instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-disconnect.html.
-
execute_multi
(sql: str) → None[source]¶ Executes a multi query that does not select any rows.
Parameters: sql (str) – The SQL statements.
-
execute_none
(sql: str, *params) → int[source]¶ Executes a query that does not select any rows. Returns the number of affected rows.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The values for the statement.
Return type:
-
execute_rows
(sql: str, *params) → List[Dict[str, Any]][source]¶ Executes a query that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The arguments for the statement.
Return type:
-
execute_singleton1
(sql: str, *params) → Any[source]¶ Executes SQL statement that selects 1 row with 1 column. Returns the value of the selected column.
Parameters: - sql (str) – The SQL calling the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type: *:
-
execute_sp_bulk
(bulk_handler: pystratum_middle.BulkHandler.BulkHandler, sql: str, *params) → int[source]¶ Executes a stored routine with designation type “bulk”. Returns the number of rows processed.
Parameters: - bulk_handler (BulkHandler) – The bulk handler for processing the selected rows.
- sql (str) – The SQL statement for calling the stored routine.
- params (iterable) – The arguments for calling the stored routine.
Return type:
-
execute_sp_log
(sql: str, *params) → int[source]¶ Executes a stored routine with designation type “log”. Returns the number of log messages.
Parameters: - sql (str) – The SQL statement for calling the stored routine.
- params (iterable) – The arguments for calling the stored routine.
Return type:
-
execute_sp_multi
(sql: str, *params) → List[List[Dict[str, Any]]][source]¶ Executes a stored routine with designation type “multi”. Returns a list of the result sets.
Parameters: - sql (str) – The SQL statement for calling the stored routine.
- params (iterable) – The arguments for calling the stored routine.
Return type:
-
execute_sp_none
(sql: str, *params) → int[source]¶ Executes a stored routine that does not select any rows. Returns the number of affected rows.
Parameters: - sql (str) – The SQL calling the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type:
-
execute_sp_row0
(sql: str, *params) → Optional[Dict[str, Any]][source]¶ Executes a stored procedure that selects 0 or 1 row. Returns the selected row or None.
Parameters: - sql (str) – The SQL call the the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type: None|dict[str,*]
-
execute_sp_row1
(sql: str, *params) → Dict[str, Any][source]¶ Executes a stored procedure that selects 1 row. Returns the selected row.
Parameters: - sql (str) – The SQL calling the the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type:
-
execute_sp_rows
(sql: str, *params) → List[Dict[str, Any]][source]¶ Executes a stored procedure that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The arguments for the statement.
Return type:
-
execute_sp_singleton0
(sql: str, *params) → Any[source]¶ Executes a stored procedure that selects 0 or 1 row with 1 column. Returns the value of selected column or None.
Parameters: - sql (str) – The SQL calling the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type:
-
execute_sp_singleton1
(sql: str, *params) → Any[source]¶ Executes a stored routine with designation type “table”, i.e a stored routine that is expected to select 1 row with 1 column.
Parameters: - sql (str) – The SQL calling the the stored procedure.
- params (iterable) – The arguments for the stored procedure.
Return type: - The value of the selected column.
-
is_alive
() → bool[source]¶ Returns whether Python is (still) connected to a MySQL or MariaDB instance.
Return type: bool
-
line_buffered
= None¶ If True log messages from stored procedures with designation type ‘log’ are line buffered (Note: In python sys.stdout is buffered by default).
-
rollback
() → None[source]¶ Rolls back the current transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-rollback.html
-
start_transaction
(consistent_snapshot: bool = False, isolation_level: str = 'READ-COMMITTED', readonly: Optional[bool] = None) → None[source]¶ Starts a transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-start-transaction.html
Parameters:
-
pystratum_mysql.MySqlDefaultConnector module¶
-
class
pystratum_mysql.MySqlDefaultConnector.
MySqlDefaultConnector
(params: Dict[str, Union[str, int]])[source]¶ Bases:
pystratum_mysql.MySqlConnector.MySqlConnector
Connects to a MySQL instance using username and password.
pystratum_mysql.MySqlMetadataDataLayer module¶
-
class
pystratum_mysql.MySqlMetadataDataLayer.
MySqlMetadataDataLayer
(io: pystratum_backend.StratumStyle.StratumStyle, connector: pystratum_mysql.MySqlConnector.MySqlConnector)[source]¶ Bases:
pystratum_common.MetadataDataLayer.MetadataDataLayer
Data layer for retrieving metadata and loading stored routines.
-
call_stored_routine
(routine_name: str) → int[source]¶ Class a stored procedure without arguments.
Parameters: routine_name (str) – The name of the procedure. Return type: int
-
check_table_exists
(table_name: str) → int[source]¶ Checks if a table exists in the current schema.
Parameters: table_name (str) – The name of the table. Return type: int
-
describe_table
(table_name: str) → List[Dict[str, Any]][source]¶ Describes a table.
Parameters: table_name (str) – The name of the table. Return type: list[dict[str,*]]
-
drop_stored_routine
(routine_type: str, routine_name: str) → None[source]¶ Drops a stored routine if it exists.
Parameters:
-
drop_temporary_table
(table_name: str) → None[source]¶ Drops a temporary table.
Parameters: table_name (str) – The name of the table.
-
execute_none
(query: str) → int[source]¶ Executes a query that does not select any rows.
Parameters: query (str) – The query. Return type: int
-
execute_rows
(query: str) → List[Dict[str, Any]][source]¶ Executes a query that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).
Parameters: query (str) – The query. Return type: list[dict[str,*]]
-
execute_singleton1
(query: str) → Any[source]¶ Executes SQL statement that selects 1 row with 1 column. Returns the value of the selected column.
Parameters: query (str) – The query. Return type:
-
get_all_table_columns
() → List[Dict[str, Union[str, int, None]]][source]¶ Selects metadata of all columns of all tables.
Return type: list[dict[str,*]]
-
get_correct_sql_mode
(sql_mode: str) → str[source]¶ Selects the SQL mode in the order as preferred by MySQL.
Parameters: sql_mode (str) – The SQL mode. Return type: str
-
get_label_tables
(regex: str) → List[Dict[str, Any]][source]¶ Selects metadata of tables with a label column.
Parameters: regex (str) – The regular expression for columns which we want to use. Return type: list[dict[str,*]]
-
get_labels_from_table
(table_name: str, id_column_name: str, label_column_name: str) → List[Dict[str, Any]][source]¶ Selects all labels from a table with labels.
Parameters: Return type:
-
get_routine_parameters
(routine_name: str) → List[Dict[str, Any]][source]¶ Selects metadata of the parameters of a stored routine.
Parameters: routine_name (str) – The name of the routine. Return type: list[dict[str,*]]
-
get_routines
() → List[Dict[str, Any]][source]¶ Selects metadata of all routines in the current schema.
Return type: list[dict[str,*]]
-