CockroachDB + Psycopg¶
CockroachDB adapter using psycopg with automatic transaction retry logic. Provides both sync and async support.
Sync Configuration¶
- class sqlspec.adapters.cockroach_psycopg.CockroachPsycopgSyncConfig[source]¶
Bases:
SyncDatabaseConfig[CrdbConnection,ConnectionPool,CockroachPsycopgSyncDriver]Configuration for CockroachDB synchronous connections using psycopg.
- driver_type¶
alias of
CockroachPsycopgSyncDriver
- __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_session(*_args, statement_config=None, follower_reads=None, staleness=None, **_kwargs)[source]¶
Provide a database session context manager.
- Return type:
CockroachPsycopgSyncSessionContext
- 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.cockroach_psycopg.CockroachPsycopgAsyncConfig[source]¶
Bases:
AsyncDatabaseConfig[AsyncCrdbConnection,AsyncConnectionPool,CockroachPsycopgAsyncDriver]Configuration for CockroachDB async connections using psycopg.
- driver_type¶
alias of
CockroachPsycopgAsyncDriver
- __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_session(*_args, statement_config=None, follower_reads=None, staleness=None, **_kwargs)[source]¶
Provide a database session context manager.
- Return type:
CockroachPsycopgAsyncSessionContext
- async provide_pool(*args, **kwargs)[source]¶
Provide pool instance.
- Return type:
AsyncConnectionPool
- 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.cockroach_psycopg.CockroachPsycopgSyncDriver[source]¶
Bases:
PsycopgSyncDriverCockroachDB sync driver using psycopg.crdb.
- handle_database_exceptions()[source]¶
Handle database-specific exceptions and wrap them appropriately.
- Return type:
CockroachPsycopgSyncExceptionHandler
- property data_dictionary: CockroachPsycopgSyncDataDictionary¶
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Async Driver¶
- class sqlspec.adapters.cockroach_psycopg.CockroachPsycopgAsyncDriver[source]¶
Bases:
PsycopgAsyncDriverCockroachDB async driver using psycopg.crdb.
- async dispatch_execute_many(cursor, statement)[source]¶
Execute SQL with multiple parameter sets (async).
- async dispatch_execute_script(cursor, statement)[source]¶
Execute SQL script with multiple statements (async).
- handle_database_exceptions()[source]¶
Handle database-specific exceptions and wrap them appropriately.
- Return type:
CockroachPsycopgAsyncExceptionHandler
- property data_dictionary: CockroachPsycopgAsyncDataDictionary¶
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Retry Configuration¶
- class sqlspec.adapters.cockroach_psycopg.CockroachPsycopgRetryConfig[source]¶
Bases:
objectCockroachDB psycopg transaction retry configuration.
- classmethod from_features(driver_features)[source]¶
Build retry config from driver feature mappings.
- Return type:
- __init__(max_retries=10, base_delay_ms=50.0, max_delay_ms=5000.0, enable_logging=True)¶
Sync Data Dictionary¶
- class sqlspec.adapters.cockroach_psycopg.data_dictionary.CockroachPsycopgSyncDataDictionary[source]¶
Bases:
SyncDataDictionaryBaseCockroachDB sync data dictionary.
- dialect: ClassVar[str] = 'cockroachdb'¶
Dialect identifier. Must be defined by subclasses as a class attribute.
- get_feature_flag(driver, feature)[source]¶
Check if CockroachDB supports a specific feature.
- Return type:
- get_optimal_type(driver, type_category)[source]¶
Get optimal CockroachDB type for a category.
- Return type:
- get_columns(driver, table=None, schema=None)[source]¶
Get column information for a table or schema.
- Return type:
- get_indexes(driver, table=None, schema=None)[source]¶
Get index metadata for a table or schema.
- Return type:
Async Data Dictionary¶
- class sqlspec.adapters.cockroach_psycopg.data_dictionary.CockroachPsycopgAsyncDataDictionary[source]¶
Bases:
AsyncDataDictionaryBaseCockroachDB async data dictionary.
- dialect: ClassVar[str] = 'cockroachdb'¶
Dialect identifier. Must be defined by subclasses as a class attribute.
- async get_feature_flag(driver, feature)[source]¶
Check if CockroachDB supports a specific feature.
- Return type:
- async get_optimal_type(driver, type_category)[source]¶
Get optimal CockroachDB type for a category.
- Return type:
- async get_columns(driver, table=None, schema=None)[source]¶
Get column information for a table or schema.
- Return type:
- async get_indexes(driver, table=None, schema=None)[source]¶
Get index metadata for a table or schema.
- Return type: