OracleDB¶
Sync and async Oracle adapter using python-oracledb. Features native pipeline mode for multi-statement batching, BLOB support, and LOB coercion with byte-length thresholds.
Sync Configuration¶
- class sqlspec.adapters.oracledb.OracleSyncConfig[source]¶
Bases:
SyncDatabaseConfig[Connection,OracleSyncConnectionPool,OracleSyncDriver]Configuration for Oracle synchronous database connections.
- driver_type¶
alias of
OracleSyncDriver
- migration_tracker_type¶
alias of
OracleSyncMigrationTracker
- __init__(*, connection_config=None, connection_instance=None, migration_config=None, statement_config=None, driver_features=None, bind_key=None, extension_config=None, **kwargs)[source]¶
Initialize Oracle synchronous configuration.
- Parameters:
connection_config¶ – Connection and pool configuration parameters.
connection_instance¶ – Existing pool instance to use.
migration_config¶ – Migration configuration.
statement_config¶ – Default SQL statement configuration.
driver_features¶ – Optional driver feature configuration (TypedDict or dict).
bind_key¶ – Optional unique identifier for this configuration.
extension_config¶ – Extension-specific configuration (e.g., Litestar plugin settings).
**kwargs¶ – Additional keyword arguments.
- create_connection()[source]¶
Create a single connection (not from pool).
- Return type:
Connection- Returns:
An Oracle Connection instance.
- provide_connection()[source]¶
Provide a connection context manager.
- Return type:
OracleSyncConnectionContext- Returns:
An Oracle Connection context manager.
- provide_session(*_args, statement_config=None, **_kwargs)[source]¶
Provide a driver session context manager.
Async Configuration¶
- class sqlspec.adapters.oracledb.OracleAsyncConfig[source]¶
Bases:
AsyncDatabaseConfig[AsyncConnection,OracleAsyncConnectionPool,OracleAsyncDriver]Configuration for Oracle asynchronous database connections.
- driver_type¶
alias of
OracleAsyncDriver
- migration_tracker_type¶
alias of
OracleAsyncMigrationTracker
- __init__(*, connection_config=None, connection_instance=None, migration_config=None, statement_config=None, driver_features=None, bind_key=None, extension_config=None, **kwargs)[source]¶
Initialize Oracle asynchronous configuration.
- Parameters:
connection_config¶ – Connection and pool configuration parameters.
connection_instance¶ – Existing pool instance to use.
migration_config¶ – Migration configuration.
statement_config¶ – Default SQL statement configuration.
driver_features¶ – Optional driver feature configuration (TypedDict or dict).
bind_key¶ – Optional unique identifier for this configuration.
extension_config¶ – Extension-specific configuration (e.g., Litestar plugin settings).
**kwargs¶ – Additional keyword arguments.
- async create_connection()[source]¶
Create a single async connection (not from pool).
- Return type:
AsyncConnection- Returns:
An Oracle AsyncConnection instance.
- provide_connection()[source]¶
Provide an async connection context manager.
- Return type:
OracleAsyncConnectionContext- Returns:
An Oracle AsyncConnection context manager.
- provide_session(*_args, statement_config=None, **_kwargs)[source]¶
Provide an async driver session context manager.
Sync Driver¶
- class sqlspec.adapters.oracledb.OracleSyncDriver[source]¶
Bases:
OraclePipelineMixin,SyncDriverAdapterBaseSynchronous Oracle Database driver.
Provides Oracle Database connectivity with parameter style conversion, error handling, and transaction management.
- dispatch_execute(cursor, statement)[source]¶
Execute single SQL statement with Oracle data handling.
- dispatch_execute_many(cursor, statement)[source]¶
Execute SQL with multiple parameter sets using Oracle batch processing.
- Parameters:
- Return type:
ExecutionResult- Returns:
Execution result with affected row count
- Raises:
ValueError – If no parameters are provided
- dispatch_execute_script(cursor, statement)[source]¶
Execute SQL script with statement splitting and parameter handling.
Parameters are embedded as static values for script execution compatibility.
- begin()[source]¶
Begin a database transaction.
Oracle handles transactions automatically, so this is a no-op.
- Return type:
- commit()[source]¶
Commit the current transaction.
- Raises:
SQLSpecError – If commit fails
- Return type:
- rollback()[source]¶
Rollback the current transaction.
- Raises:
SQLSpecError – If rollback fails
- Return type:
- with_cursor(connection)[source]¶
Create context manager for Oracle cursor.
- Parameters:
connection¶ (
Connection) – Oracle database connection- Return type:
OracleSyncCursor- Returns:
Context manager for cursor operations
- handle_database_exceptions()[source]¶
Handle database-specific exceptions and wrap them appropriately.
- Return type:
OracleSyncExceptionHandler
- select_to_arrow(statement, /, *parameters, statement_config=None, return_format='table', native_only=False, batch_size=None, arrow_schema=None, **kwargs)[source]¶
Execute query and return results as Apache Arrow format using Oracle native support.
This implementation uses Oracle’s native execute_df()/fetch_df_all() methods which return OracleDataFrame objects with Arrow PyCapsule interface, providing zero-copy data transfer and 5-10x performance improvement over dict conversion. If native Arrow is unavailable and native_only is False, it falls back to the conversion path.
- Parameters:
statement¶ – SQL query string, Statement, or QueryBuilder
*parameters¶ – Query parameters (same format as execute()/select())
statement_config¶ – Optional statement configuration override
return_format¶ – “table” for pyarrow.Table (default), “batch” for RecordBatch, “batches” for list of RecordBatch, “reader” for RecordBatchReader
native_only¶ – If True, raise error if native Arrow is unavailable
batch_size¶ – Rows per batch when using “batch” or “batches” format
arrow_schema¶ – Optional pyarrow.Schema for type casting
**kwargs¶ – Additional keyword arguments
- Returns:
ArrowResult containing pyarrow.Table or RecordBatch
Examples
>>> result = driver.select_to_arrow( ... "SELECT * FROM users WHERE age > :1", (18,) ... ) >>> df = result.to_pandas() >>> print(df.head())
- execute_stack(stack, *, continue_on_error=False)[source]¶
Execute a StatementStack using Oracle’s pipeline when available.
- Return type:
- select_to_storage(statement, destination, /, *parameters, statement_config=None, partitioner=None, format_hint=None, telemetry=None, **kwargs)[source]¶
Execute a query and stream Arrow-formatted output to storage (sync).
- load_from_arrow(table, source, *, partitioner=None, overwrite=False, telemetry=None)[source]¶
Load Arrow data into Oracle using batched executemany calls.
- load_from_storage(table, source, *, file_format, partitioner=None, overwrite=False)[source]¶
Load staged artifacts into Oracle.
- Return type:
- property data_dictionary: OracledbSyncDataDictionary¶
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Async Driver¶
- class sqlspec.adapters.oracledb.OracleAsyncDriver[source]¶
Bases:
OraclePipelineMixin,AsyncDriverAdapterBaseAsynchronous Oracle Database driver.
Provides Oracle Database connectivity with parameter style conversion, error handling, and transaction management for async operations.
- async dispatch_execute(cursor, statement)[source]¶
Execute single SQL statement with Oracle data handling.
- async dispatch_execute_many(cursor, statement)[source]¶
Execute SQL with multiple parameter sets using Oracle batch processing.
- Parameters:
- Return type:
ExecutionResult- Returns:
Execution result with affected row count
- Raises:
ValueError – If no parameters are provided
- async dispatch_execute_script(cursor, statement)[source]¶
Execute SQL script with statement splitting and parameter handling.
Parameters are embedded as static values for script execution compatibility.
- async begin()[source]¶
Begin a database transaction.
Oracle handles transactions automatically, so this is a no-op.
- Return type:
- async commit()[source]¶
Commit the current transaction.
- Raises:
SQLSpecError – If commit fails
- Return type:
- async rollback()[source]¶
Rollback the current transaction.
- Raises:
SQLSpecError – If rollback fails
- Return type:
- with_cursor(connection)[source]¶
Create context manager for Oracle cursor.
- Parameters:
connection¶ (
AsyncConnection) – Oracle database connection- Return type:
OracleAsyncCursor- Returns:
Context manager for cursor operations
- handle_database_exceptions()[source]¶
Handle database-specific exceptions and wrap them appropriately.
- Return type:
OracleAsyncExceptionHandler
- async select_to_arrow(statement, /, *parameters, statement_config=None, return_format='table', native_only=False, batch_size=None, arrow_schema=None, **kwargs)[source]¶
Execute query and return results as Apache Arrow format using Oracle native support.
This implementation uses Oracle’s native execute_df()/fetch_df_all() methods which return OracleDataFrame objects with Arrow PyCapsule interface, providing zero-copy data transfer and 5-10x performance improvement over dict conversion. If native Arrow is unavailable and native_only is False, it falls back to the conversion path.
- Parameters:
statement¶ – SQL query string, Statement, or QueryBuilder
*parameters¶ – Query parameters (same format as execute()/select())
statement_config¶ – Optional statement configuration override
return_format¶ – “table” for pyarrow.Table (default), “batch” for RecordBatch, “batches” for list of RecordBatch, “reader” for RecordBatchReader
native_only¶ – If True, raise error if native Arrow is unavailable
batch_size¶ – Rows per batch when using “batch” or “batches” format
arrow_schema¶ – Optional pyarrow.Schema for type casting
**kwargs¶ – Additional keyword arguments
- Returns:
ArrowResult containing pyarrow.Table or RecordBatch
Examples
>>> result = await driver.select_to_arrow( ... "SELECT * FROM users WHERE age > :1", (18,) ... ) >>> df = result.to_pandas() >>> print(df.head())
- async execute_stack(stack, *, continue_on_error=False)[source]¶
Execute a StatementStack using Oracle’s pipeline when available.
- Return type:
- async select_to_storage(statement, destination, /, *parameters, statement_config=None, partitioner=None, format_hint=None, telemetry=None, **kwargs)[source]¶
Execute a query and write Arrow-compatible output to storage (async).
- async load_from_arrow(table, source, *, partitioner=None, overwrite=False, telemetry=None)[source]¶
Asynchronously load Arrow data into Oracle.
- async load_from_storage(table, source, *, file_format, partitioner=None, overwrite=False)[source]¶
Asynchronously load staged artifacts into Oracle.
- Return type:
- property data_dictionary: OracledbAsyncDataDictionary¶
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries