Events¶
Pub/sub event channel system with database-backed queue support. Provides both sync and async channels with listener management and native backend integration for databases that support LISTEN/NOTIFY.
Channels¶
- class sqlspec.extensions.events.AsyncEventChannel[source]¶
Bases:
objectEvent channel for asynchronous database configurations.
- async iter_events(channel, *, poll_interval=None)[source]¶
Yield events as they become available.
- Return type:
- class sqlspec.extensions.events.SyncEventChannel[source]¶
Bases:
objectEvent channel for synchronous database configurations.
- iter_events(channel, *, poll_interval=None)[source]¶
Yield events as they become available.
- Return type:
Listeners¶
Event Queue¶
- class sqlspec.extensions.events.AsyncTableEventQueue[source]¶
Bases:
_BaseTableEventQueueAsync table queue implementation.
- class sqlspec.extensions.events.SyncTableEventQueue[source]¶
Bases:
_BaseTableEventQueueSync table queue implementation.
Store¶
- class sqlspec.extensions.events.BaseEventQueueStore[source]¶
-
Base class for adapter-specific event queue DDL generators.
This class provides a hook-based pattern for DDL generation. Adapters only need to override _column_types() and optionally any hook methods for dialect-specific variations:
_string_type(length): String type syntax (default: VARCHAR(N))
_integer_type(): Integer type syntax (default: INTEGER)
_timestamp_default(): Timestamp default expression (default: CURRENT_TIMESTAMP)
_primary_key_syntax(): Inline PRIMARY KEY clause (default: empty, PK on column)
_table_clause(): Additional table options (default: empty)
For complex dialects (Oracle PL/SQL, BigQuery CLUSTER BY), adapters may override _build_create_table_sql() directly.
- property settings: dict[str, TypeAliasForwardRef('typing.Any')]¶
Return extension settings for adapters to inspect.
Models¶
Protocols¶
- class sqlspec.extensions.events.AsyncEventBackendProtocol[source]¶
Bases:
ProtocolProtocol for async event backends.
All async event backends (native or queue-based) must implement these methods.
- __init__(*args, **kwargs)¶
- class sqlspec.extensions.events.SyncEventBackendProtocol[source]¶
Bases:
ProtocolProtocol for sync event backends.
All sync event backends (native or queue-based) must implement these methods.
- __init__(*args, **kwargs)¶
Payload Helpers¶
- sqlspec.extensions.events.encode_notify_payload(event_id, payload, metadata)[source]¶
Encode event data as JSON for NOTIFY payload.
- Raises:
EventChannelError – If the encoded payload exceeds PostgreSQL’s 8KB limit.
- Return type:
Utility Functions¶
- sqlspec.extensions.events.load_native_backend(config, backend_name, extension_settings)[source]¶
Load adapter-specific native backend if available.
- sqlspec.extensions.events.resolve_poll_interval(poll_interval, default)[source]¶
Resolve poll interval with validation.
- Return type: