mysql-connector-python#
Official MySQL driver with both sync and async support.
Sync Configuration#
- class sqlspec.adapters.mysqlconnector.MysqlConnectorSyncConfig[source]#
Bases:
SyncDatabaseConfig[MySQLConnection,MysqlConnectorConnectionPool,MysqlConnectorSyncDriver]Configuration for mysql-connector synchronous MySQL connections.
- driver_type#
alias of
MysqlConnectorSyncDriver
- connection_type#
alias of
MySQLConnection
- __init__(*, connection_config=None, connection_instance=None, migration_config=None, statement_config=None, driver_features=None, bind_key=None, extension_config=None, observability_config=None, **kwargs)[source]#
- get_signature_namespace()[source]#
Get the signature namespace for this database configuration.
Returns a dictionary of type names to objects (classes, functions, or other callables) that should be registered with Litestar's signature namespace to prevent serialization attempts on database-specific structures.
Async Configuration#
- class sqlspec.adapters.mysqlconnector.MysqlConnectorAsyncConfig[source]#
Bases:
NoPoolAsyncConfig[MySQLConnection,MysqlConnectorAsyncDriver]Configuration for mysql-connector async MySQL connections.
- driver_type#
alias of
MysqlConnectorAsyncDriver
- connection_type#
alias of
MySQLConnection
- __init__(*, connection_config=None, connection_instance=None, migration_config=None, statement_config=None, driver_features=None, bind_key=None, extension_config=None, observability_config=None, **kwargs)[source]#
- provide_connection(*args, **kwargs)[source]#
Provide a database connection context manager.
- Return type:
MysqlConnectorAsyncConnectionContext
- provide_session(*_args, statement_config=None, **_kwargs)[source]#
Provide a database session context manager.
- Return type:
MysqlConnectorAsyncSessionContext
- get_signature_namespace()[source]#
Get the signature namespace for this database configuration.
Returns a dictionary of type names to objects (classes, functions, or other callables) that should be registered with Litestar's signature namespace to prevent serialization attempts on database-specific structures.
Sync Driver#
- class sqlspec.adapters.mysqlconnector.MysqlConnectorSyncDriver[source]#
Bases:
SyncDriverAdapterBaseMySQL/MariaDB database driver using mysql-connector sync library.
- __init__(connection, statement_config=None, driver_features=None)[source]#
Initialize driver adapter with connection and configuration.
- Parameters:
connection¶ (
MySQLConnection) -- Database connection instancestatement_config¶ (
StatementConfig|None) -- Statement configuration for the driverdriver_features¶ (
dict[str, typing.Any] |None) -- Driver-specific features like extensions, secrets, and connection callbacksobservability¶ -- Optional runtime handling lifecycle hooks, observers, and spans
- dispatch_execute(cursor, statement)[source]#
Execute a single SQL statement.
Must be implemented by each driver for database-specific execution logic.
- dispatch_execute_many(cursor, statement)[source]#
Execute SQL with multiple parameter sets (executemany).
Must be implemented by each driver for database-specific executemany logic.
- dispatch_execute_script(cursor, statement)[source]#
Execute a SQL script containing multiple statements.
Default implementation splits the script and executes statements individually. Drivers can override for database-specific script execution methods.
- with_cursor(connection)[source]#
Create and return a context manager for cursor acquisition and cleanup.
Returns a context manager that yields a cursor for database operations. Concrete implementations handle database-specific cursor creation and cleanup.
- Return type:
MysqlConnectorSyncCursor
- dispatch_select_stream(statement, chunk_size)[source]#
Return a native mysql-connector row stream backed by an unbuffered cursor.
- handle_database_exceptions()[source]#
Handle database-specific exceptions and wrap them appropriately.
- Return type:
MysqlConnectorSyncExceptionHandler- Returns:
Exception handler with deferred exception pattern for mypyc compatibility. The handler stores mapped exceptions in pending_exception rather than raising from __exit__ to avoid ABI boundary violations.
- select_to_storage(statement, destination, /, *parameters, statement_config=None, partitioner=None, format_hint=None, telemetry=None, **kwargs)[source]#
Stream a SELECT statement directly into storage.
- Parameters:
statement_config¶ (
StatementConfig|None) -- Optional statement configuration.partitioner¶ (
dict[str,object] |None) -- Optional partitioner configuration.format_hint¶ (
Optional[Literal['jsonl','json','parquet','arrow-ipc','csv']]) -- Optional format hint for storage.telemetry¶ (
StorageTelemetry|None) -- Optional telemetry dict to merge.
- Return type:
- Returns:
StorageBridgeJob with execution telemetry.
- load_from_arrow(table, source, *, partitioner=None, overwrite=False, telemetry=None)[source]#
Load Arrow data into the target table.
- Parameters:
- Return type:
- Returns:
StorageBridgeJob with execution telemetry.
- load_from_storage(table, source, *, file_format, partitioner=None, overwrite=False)[source]#
Load artifacts from storage into the target table.
- property data_dictionary: MysqlConnectorSyncDataDictionary#
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Async Driver#
- class sqlspec.adapters.mysqlconnector.MysqlConnectorAsyncDriver[source]#
Bases:
AsyncDriverAdapterBaseMySQL/MariaDB database driver using mysql-connector async library.
- __init__(connection, statement_config=None, driver_features=None)[source]#
Initialize driver adapter with connection and configuration.
- Parameters:
connection¶ (
MySQLConnection) -- Database connection instancestatement_config¶ (
StatementConfig|None) -- Statement configuration for the driverdriver_features¶ (
dict[str, typing.Any] |None) -- Driver-specific features like extensions, secrets, and connection callbacksobservability¶ -- Optional runtime handling lifecycle hooks, observers, and spans
- async dispatch_execute(cursor, statement)[source]#
Execute a single SQL statement.
Must be implemented by each driver for database-specific execution logic.
- async dispatch_execute_many(cursor, statement)[source]#
Execute SQL with multiple parameter sets (executemany).
Must be implemented by each driver for database-specific executemany logic.
- async dispatch_execute_script(cursor, statement)[source]#
Execute a SQL script containing multiple statements.
Default implementation splits the script and executes statements individually. Drivers can override for database-specific script execution methods.
- with_cursor(connection)[source]#
Create and return an async context manager for cursor acquisition and cleanup.
Returns an async context manager that yields a cursor for database operations. Concrete implementations handle database-specific cursor creation and cleanup.
- Return type:
MysqlConnectorAsyncCursor
- dispatch_select_stream(statement, chunk_size)[source]#
Return a native mysql-connector row stream backed by an unbuffered cursor.
- handle_database_exceptions()[source]#
Handle database-specific exceptions and wrap them appropriately.
- Return type:
MysqlConnectorAsyncExceptionHandler- Returns:
Exception handler with deferred exception pattern for mypyc compatibility. The handler stores mapped exceptions in pending_exception rather than raising from __aexit__ to avoid ABI boundary violations.
- async select_to_storage(statement, destination, /, *parameters, statement_config=None, partitioner=None, format_hint=None, telemetry=None, **kwargs)[source]#
Stream a SELECT statement directly into storage.
- Parameters:
statement_config¶ (
StatementConfig|None) -- Optional statement configuration.partitioner¶ (
dict[str,object] |None) -- Optional partitioner configuration.format_hint¶ (
Optional[Literal['jsonl','json','parquet','arrow-ipc','csv']]) -- Optional format hint for storage.telemetry¶ (
StorageTelemetry|None) -- Optional telemetry dict to merge.
- Return type:
- Returns:
StorageBridgeJob with execution telemetry.
- async load_from_arrow(table, source, *, partitioner=None, overwrite=False, telemetry=None)[source]#
Load Arrow data into the target table.
- Parameters:
- Return type:
- Returns:
StorageBridgeJob with execution telemetry.
- Raises:
NotImplementedError -- If not implemented.
- async load_from_storage(table, source, *, file_format, partitioner=None, overwrite=False)[source]#
Load artifacts from storage into the target table.
- property data_dictionary: MysqlConnectorAsyncDataDictionary#
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Sync Data Dictionary#
- class sqlspec.adapters.mysqlconnector.data_dictionary.MysqlConnectorSyncDataDictionary[source]#
Bases:
SyncDataDictionaryBaseMySQL-specific sync data dictionary.
- dialect: ClassVar[str] = 'mysql'#
Dialect identifier. Must be defined by subclasses as a class attribute.
- get_version(driver)[source]#
Get MySQL database version information.
- Return type:
VersionInfo|None
- get_feature_flag(driver, feature)[source]#
Check if MySQL database supports a specific feature.
- Return type:
- get_metadata_capabilities(driver, domains=None)[source]#
Get data-dictionary capability profile.
- Return type:
MetadataCapabilityProfile
- get_schemas(driver)[source]#
Get schema metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_objects(driver, schema=None)[source]#
Get object metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_table_details(driver, table, schema=None)[source]#
Get rich table metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_constraints(driver, table=None, schema=None)[source]#
Get constraint metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_views(driver, schema=None)[source]#
Get view metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_routines(driver, schema=None)[source]#
Get routine metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_privileges(driver, object_name=None, schema=None)[source]#
Get privilege metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- get_ddl(driver, object_name, schema=None, *, object_type='table', include_dependencies=True, prefer_native=True, redact=True)[source]#
Get native SHOW CREATE output and replay-sensitive context for a table.
- Return type:
DDLResult
- get_system_metadata(driver, request=None, **kwargs)[source]#
Get opt-in system metadata from performance_schema or sys.
- Return type:
SystemMetadataResult
- get_optimal_type(driver, type_category)[source]#
Get optimal MySQL type for a category.
- Return type:
- get_tables(driver, schema=None)[source]#
Get tables sorted by topological dependency order using the MySQL catalog.
- Return type:
list[TableMetadata]
- get_columns(driver, table=None, schema=None)[source]#
Get column information for a table or schema.
- Return type:
list[ColumnMetadata]
Async Data Dictionary#
- class sqlspec.adapters.mysqlconnector.data_dictionary.MysqlConnectorAsyncDataDictionary[source]#
Bases:
AsyncDataDictionaryBaseMySQL-specific async data dictionary.
- dialect: ClassVar[str] = 'mysql'#
Dialect identifier. Must be defined by subclasses as a class attribute.
- async get_version(driver)[source]#
Get MySQL database version information.
- Return type:
VersionInfo|None
- async get_feature_flag(driver, feature)[source]#
Check if MySQL database supports a specific feature.
- Return type:
- async get_metadata_capabilities(driver, domains=None)[source]#
Get data-dictionary capability profile.
- Return type:
MetadataCapabilityProfile
- async get_schemas(driver)[source]#
Get schema metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_objects(driver, schema=None)[source]#
Get object metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_table_details(driver, table, schema=None)[source]#
Get rich table metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_constraints(driver, table=None, schema=None)[source]#
Get constraint metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_views(driver, schema=None)[source]#
Get view metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_routines(driver, schema=None)[source]#
Get routine metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_privileges(driver, object_name=None, schema=None)[source]#
Get privilege metadata from INFORMATION_SCHEMA.
- Return type:
MetadataResult
- async get_ddl(driver, object_name, schema=None, *, object_type='table', include_dependencies=True, prefer_native=True, redact=True)[source]#
Get native SHOW CREATE output and replay-sensitive context for a table.
- Return type:
DDLResult
- async get_system_metadata(driver, request=None, **kwargs)[source]#
Get opt-in system metadata from performance_schema or sys.
- Return type:
SystemMetadataResult
- async get_optimal_type(driver, type_category)[source]#
Get optimal MySQL type for a category.
- Return type:
- async get_tables(driver, schema=None)[source]#
Get tables sorted by topological dependency order using the MySQL catalog.
- Return type:
list[TableMetadata]
- async get_columns(driver, table=None, schema=None)[source]#
Get column information for a table or schema.
- Return type:
list[ColumnMetadata]