db2 Adapter¶
from sqlspec.adapters.db2 import (
Db2AsyncConfig,
Db2AsyncDriver,
Db2AsyncExceptionHandler,
Db2AsyncPoolParams,
Db2ConnectionParams,
Db2DriverFeatures,
Db2PoolParams,
Db2SyncConfig,
Db2SyncDriver,
Db2SyncExceptionHandler,
)
Synchronous and asynchronous IBM Db2 LUW adapters built on ibm_db. Inherited execution methods are documented on SyncDriverAdapterBase and AsyncDriverAdapterBase. See the IBM Db2 Setup Guide for usage examples.
Configuration & Parameters¶
Db2SyncConfig
¶
Bases: SyncDatabaseConfig[Db2SyncConnection, Db2SyncConnectionPool, Db2SyncDriver]
Configuration for IBM Db2 synchronous connections.
Db2AsyncConfig
¶
Bases: AsyncDatabaseConfig[Db2AsyncConnection, Db2AsyncConnectionPool, Db2AsyncDriver]
Configuration for IBM Db2 asynchronous connections over ibm_db_dbi.AsyncConnection.
Db2ConnectionParams
¶
Bases: TypedDict
IBM Db2 CLI connection parameters compiled into a KEY=VALUE;... DSN.
Attributes:
| Name | Type | Description |
|---|---|---|
database |
NotRequired[str]
|
Database name or cataloged alias mapped to the |
hostname |
NotRequired[str]
|
Db2 server hostname mapped to |
port |
NotRequired[int]
|
Db2 TCP listener port mapped to |
protocol |
NotRequired[str]
|
Communications protocol mapped to |
user |
NotRequired[str]
|
Authentication username mapped to the |
password |
NotRequired[str]
|
Authentication password mapped to the |
current_schema |
NotRequired[str]
|
Default SQL schema mapped to the |
security |
NotRequired[str]
|
Transport security mode mapped to |
ssl_server_certificate |
NotRequired[str]
|
Server certificate file path mapped to the |
authentication |
NotRequired[str]
|
Db2 authentication mechanism mapped to the |
connect_timeout |
NotRequired[int]
|
Connection establishment timeout in seconds mapped to |
autocommit |
NotRequired[bool]
|
Initial connection autocommit state applied via |
dsn |
NotRequired[str]
|
Base |
extra |
NotRequired[dict[str, str | int | bool]]
|
Additional CLI keywords appended verbatim to the compiled DSN string. |
Db2PoolParams
¶
Bases: Db2ConnectionParams
IBM Db2 thread-local connection pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pool_recycle_seconds |
NotRequired[int]
|
Maximum connection age in seconds before replacement (defaults to |
health_check_interval |
NotRequired[float]
|
Idle seconds elapsed before a pooled connection is pinged on reuse (defaults to |
Db2AsyncPoolParams
¶
Bases: Db2PoolParams
IBM Db2 bounded asyncio connection pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
max_size |
NotRequired[int]
|
Maximum number of connections checked out or opening concurrently (defaults to |
acquire_timeout |
NotRequired[float]
|
Maximum seconds to wait for a free connection before raising |
Db2DriverFeatures
¶
Bases: TypedDict
IBM Db2 driver feature flags controlling JSON codecs, column casing, and event queues.
Attributes:
| Name | Type | Description |
|---|---|---|
json_serializer |
NotRequired[Callable[[Any], str]]
|
Serializer converting dict/list parameters to JSON text (defaults to |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Deserializer parsing JSON text payloads (defaults to |
on_connection_create |
NotRequired[Callable[[Any], Any]]
|
Callback invoked with the raw |
enable_events |
NotRequired[bool]
|
Enable SQLSpec table-backed event channel support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event queue backend name ( |
enable_lowercase_column_names |
NotRequired[bool]
|
Normalize unquoted uppercase Db2 column names to lowercase (defaults to |
Driver & Pool¶
Db2SyncDriver
¶
Db2AsyncDriver
¶
Db2SyncExceptionHandler
¶
Bases: BaseSyncExceptionHandler
Context manager that maps ibm_db_dbi errors to SQLSpec exceptions.
Exceptions that do not come from the driver propagate unchanged.
Db2AsyncExceptionHandler
¶
Bases: BaseAsyncExceptionHandler
Async context manager that maps ibm_db_dbi errors to SQLSpec exceptions.
Exceptions that do not come from the driver propagate unchanged.
Extension Stores¶
Db2SyncStore
¶
Bases: BaseSQLSpecStore['Db2SyncConfig']
IBM Db2-backed session store using synchronous Db2 sessions.
Every timestamp written or compared is a naive-UTC value bound from Python, so expiry does not depend on the server's time zone.
Db2AsyncStore
¶
Bases: BaseSQLSpecStore['Db2AsyncConfig']
IBM Db2-backed session store using asynchronous Db2 sessions.
Runs the same statements with the same parameters as Db2SyncStore; every timestamp
written or compared is a naive-UTC value bound from Python.
Db2SyncADKStore
¶
Bases: _Db2ADKStoreMixin, BaseSyncADKStore[Db2SyncConfig]
Synchronous IBM Db2 ADK session/event store.
Db2AsyncADKStore
¶
Bases: _Db2ADKStoreMixin, BaseAsyncADKStore[Db2AsyncConfig]
Asynchronous IBM Db2 ADK session/event store.
Db2SyncADKMemoryStore
¶
Bases: _Db2ADKMemoryStoreMixin, BaseSyncADKMemoryStore[Db2SyncConfig]
IBM Db2 ADK memory store for synchronous configs.
Db2AsyncADKMemoryStore
¶
Bases: _Db2ADKMemoryStoreMixin, BaseAsyncADKMemoryStore[Db2AsyncConfig]
IBM Db2 ADK memory store for asynchronous configs.
Db2SyncEventQueueStore
¶
Bases: _Db2EventStoreMixin, BaseEventQueueStore[Db2SyncConfig]
IBM Db2 event queue store for synchronous configs.
Db2AsyncEventQueueStore
¶
Bases: _Db2EventStoreMixin, BaseEventQueueStore[Db2AsyncConfig]
IBM Db2 event queue store for asynchronous configs.