CockroachDB + AsyncPG#
CockroachDB adapter using asyncpg with automatic transaction retry logic.
Configuration#
- class sqlspec.adapters.cockroach_asyncpg.CockroachAsyncpgConfig[source]#
Bases:
AsyncDatabaseConfig[PoolConnectionProxy,Pool,CockroachAsyncpgDriver]Configuration for CockroachDB using AsyncPG.
- driver_type#
alias of
CockroachAsyncpgDriver
- connection_type#
alias of
PoolConnectionProxy
- __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:
CockroachAsyncpgSessionContext
- 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.
Driver#
- class sqlspec.adapters.cockroach_asyncpg.CockroachAsyncpgDriver[source]#
Bases:
AsyncpgDriverCockroachDB AsyncPG driver with retry support.
- __init__(connection, statement_config=None, driver_features=None)[source]#
Initialize driver adapter with connection and configuration.
- Parameters:
connection¶ (
PoolConnectionProxy) -- 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 run_transaction_with_retry(operation)[source]#
Execute a full CockroachDB transaction callback with serialization retries.
- Return type:
TypeVar(_T)
- async dispatch_execute(cursor, statement)[source]#
Execute single SQL statement.
Handles both SELECT queries and non-SELECT operations.
- async dispatch_execute_many(cursor, statement)[source]#
Execute SQL with multiple parameter sets using AsyncPG's executemany.
- async dispatch_execute_script(cursor, statement)[source]#
Execute SQL script with statement splitting and parameter handling.
- handle_database_exceptions()[source]#
Handle database exceptions with PostgreSQL error codes.
- Return type:
CockroachAsyncpgExceptionHandler
- property data_dictionary: CockroachAsyncpgDataDictionary#
Get the data dictionary for this driver.
- Returns:
Data dictionary instance for metadata queries
Retry Configuration#
Data Dictionary#
- class sqlspec.adapters.cockroach_asyncpg.data_dictionary.CockroachAsyncpgDataDictionary[source]#
Bases:
AsyncDataDictionaryBaseCockroachDB async data dictionary (AsyncPG).
- dialect: ClassVar[str] = 'cockroachdb'#
Dialect identifier. Must be defined by subclasses as a class attribute.
- async get_metadata_capabilities(driver, domains=None)[source]#
Get CockroachDB data-dictionary capability profile.
- Return type:
MetadataCapabilityProfile
- async get_system_metadata_capabilities(driver, domains=None)[source]#
Get CockroachDB opt-in system metadata capability disclosures.
- async get_objects(driver, schema=None)[source]#
Get database object metadata.
- Return type:
MetadataResult
- async get_table_details(driver, table, schema=None)[source]#
Get rich table metadata.
- Return type:
MetadataResult
- async get_constraints(driver, table=None, schema=None)[source]#
Get constraint metadata.
- Return type:
MetadataResult
- async get_privileges(driver, object_name=None, schema=None)[source]#
Get privilege metadata.
- Return type:
MetadataResult
- async get_dependencies(driver, object_name=None, schema=None)[source]#
Get stable dependency metadata.
- Return type:
MetadataResult
- async get_ddl(driver, object_name, schema=None, *, object_type='table', include_dependencies=True, prefer_native=True, redact=True)[source]#
Get lossy CockroachDB DDL status without parameterized identifiers.
- Return type:
DDLResult
- async get_system_metadata(driver, request=None, **kwargs)[source]#
Get opt-in CockroachDB system metadata.
- Return type:
SystemMetadataResult
- async get_version(driver)[source]#
Get database version information.
- Parameters:
driver¶ (
CockroachAsyncpgDriver) -- Async database driver instance- Return type:
VersionInfo|None- Returns:
Version information or None if detection fails
- async get_feature_flag(driver, feature)[source]#
Check if database supports a specific feature.
- Parameters:
driver¶ (
CockroachAsyncpgDriver) -- Async database driver instance
- Return type:
- Returns:
True if feature is supported, False otherwise
- async get_optimal_type(driver, type_category)[source]#
Get optimal database type for a category.
- Parameters:
driver¶ (
CockroachAsyncpgDriver) -- Async database driver instance
- Return type:
- Returns:
Database-specific type name
- async get_columns(driver, table=None, schema=None)[source]#
Get column information for a table or schema.
- async get_indexes(driver, table=None, schema=None)[source]#
Get index information for a table or schema.