sqlanywhere Adapter¶
from sqlspec.adapters.sqlanywhere import (
SqlanywhereConfig,
SqlanywhereConnectionParams,
SqlanywhereConnectionPool,
SqlanywhereDriver,
SqlanywhereDriverFeatures,
SqlanywhereExceptionHandler,
SqlanywherePoolParams,
SqlanywhereSyncDataDictionary,
SqlanywhereSyncMigrationTracker,
)
Synchronous SAP SQL Anywhere 12+ adapter built on sqlanydb (dbcapi C library). Inherited execution methods are documented on SyncDriverAdapterBase. See the SAP SQL Anywhere Setup Guide for engine connection parameters and pooling, and the SQL Anywhere Data Dictionary & SQL Catalog for system catalog introspection queries.
Configuration & Parameters¶
SqlanywhereConfig
¶
SqlanywhereConfig(
*,
connection_config: SqlanywherePoolParams | dict[str, Any] | None = None,
connection_instance: SqlanywhereConnectionPool | None = None,
migration_config: dict[str, Any] | None = None,
statement_config: StatementConfig | None = None,
driver_features: SqlanywhereDriverFeatures | dict[str, Any] | None = None,
bind_key: str | None = None,
extension_config: ExtensionConfigs | None = None,
observability_config: ObservabilityConfig | None = None,
**kwargs: Any,
)
Bases: SyncDatabaseConfig[SqlanywhereConnection, SqlanywhereConnectionPool, SqlanywhereDriver]
Configuration for SAP SQL Anywhere synchronous connections over sqlanydb.
Methods:
| Name | Description |
|---|---|
create_connection |
Open a standalone SAP SQL Anywhere connection owned by the caller. |
get_signature_namespace |
|
get_event_runtime_hints |
|
Attributes:
| Name | Type | Description |
|---|---|---|
driver_type |
type[SqlanywhereDriver]
|
|
connection_type |
type[SqlanywhereConnection]
|
|
migration_tracker_type |
type[SqlanywhereSyncMigrationTracker]
|
|
supports_transactional_ddl |
bool
|
|
supports_migration_schemas |
bool
|
|
supports_native_arrow_export |
bool
|
|
supports_native_arrow_import |
bool
|
|
supports_native_parquet_export |
bool
|
|
supports_native_parquet_import |
bool
|
|
supports_native_row_streaming |
bool
|
|
type_coercion_capabilities |
TypeCoercionCapabilities
|
|
create_connection
¶
Open a standalone SAP SQL Anywhere connection owned by the caller.
SqlanywhereConnectionParams
¶
Bases: TypedDict
SAP SQL Anywhere connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
uid |
NotRequired[str]
|
User ID / login name for authentication. |
user |
NotRequired[str]
|
Alias for |
username |
NotRequired[str]
|
Alias for |
pwd |
NotRequired[str]
|
Password for authentication. |
password |
NotRequired[str]
|
Alias for |
dbn |
NotRequired[str]
|
Database name on the SQL Anywhere server. |
database |
NotRequired[str]
|
Alias for |
db |
NotRequired[str]
|
Alias for |
eng |
NotRequired[str]
|
SQL Anywhere database engine name. |
server |
NotRequired[str]
|
Alias for |
engine |
NotRequired[str]
|
Alias for |
server_name |
NotRequired[str]
|
Alias for |
dbf |
NotRequired[str]
|
Database file path for local or embedded engines. |
database_file |
NotRequired[str]
|
Alias for |
host |
NotRequired[str]
|
TCP hostname or IP address of the server. |
port |
NotRequired[int | str]
|
TCP port number of the server. |
dsn |
NotRequired[str]
|
ODBC data source name. |
links |
NotRequired[str]
|
Network communications links protocol configuration. |
cset |
NotRequired[str]
|
Character set used for character data conversion. |
extra |
NotRequired[dict[str, Any]]
|
Additional connection parameters passed to the driver. |
SqlanywherePoolParams
¶
Bases: SqlanywhereConnectionParams
SAP SQL Anywhere pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pool_min_size |
NotRequired[int]
|
Minimum number of connections maintained in the pool. |
pool_max_size |
NotRequired[int]
|
Maximum number of connections allowed in the pool. |
pool_timeout |
NotRequired[float]
|
Seconds to wait for a connection before timing out. |
pool_recycle_seconds |
NotRequired[int]
|
Maximum age in seconds before a connection is recycled. |
health_check_interval |
NotRequired[float]
|
Interval in seconds between background health checks. |
SqlanywhereDriverFeatures
¶
Bases: TypedDict
SAP SQL Anywhere driver feature flags.
Attributes:
| Name | Type | Description |
|---|---|---|
json_serializer |
NotRequired[Callable[[Any], str]]
|
Custom callable for serializing objects to JSON strings. |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Custom callable for deserializing JSON strings. |
on_connection_create |
NotRequired[Callable[[SqlanywhereConnection], None]]
|
Callback invoked immediately when a new connection is established. |
enable_events |
NotRequired[bool]
|
Enable database event listening. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Backend mechanism used for dispatching events. |
Driver, Pool & Data Dictionary¶
SqlanywhereDriver
¶
SqlanywhereDriver(
connection: SqlanywhereConnection,
statement_config: StatementConfig | None = None,
driver_features: dict[str, Any] | None = None,
)
Bases: SyncDriverAdapterBase
SAP SQL Anywhere database driver using sqlanydb.
Attributes:
| Name | Type | Description |
|---|---|---|
dialect |
|
|
data_dictionary |
SqlanywhereSyncDataDictionary
|
|
SqlanywhereExceptionHandler
¶
SqlanywhereConnectionPool
¶
SqlanywhereConnectionPool(
connection_parameters: dict[str, Any],
min_size: int = 1,
max_size: int = 10,
timeout: float = 30.0,
recycle_seconds: int = 86400,
health_check_interval: float = 30.0,
on_connection_create: Callable[[SqlanywhereConnection], None] | None = None,
)
Thread-local connection manager for SAP SQL Anywhere over sqlanydb.
Methods:
| Name | Description |
|---|---|
new_connection |
Open a standalone SAP SQL Anywhere connection via |
get_connection |
Yield a thread-local SQL Anywhere connection. |
close |
Close every connection opened by this pool. |
acquire |
Acquire a healthy thread-local connection. |
release |
Release a checked-out connection back to the thread-local slot. |
size |
Return the number of active connections registered with this pool. |
checked_out |
Return the number of currently checked-out connections. |
SqlanywhereSyncDataDictionary
¶
Bases: SyncDataDictionaryBase
Synchronous SAP SQL Anywhere data dictionary.
Attributes:
| Name | Type | Description |
|---|---|---|
dialect |
str
|
|
SqlanywhereSyncMigrationTracker
¶
SqlanywhereSyncMigrationTracker(
version_table_name: str = "ddl_migrations",
version_table_schema: str | None = None,
)
Bases: SqlanywhereMigrationTrackerMixin, SyncMigrationTracker
Sync migration tracker using SAP SQL Anywhere DDL.
Extension Stores & Configs¶
SqlanywhereStore
¶
SqlanywhereStore(config: SqlanywhereConfig)
Bases: BaseSQLSpecStore['SqlanywhereConfig']
SAP SQL Anywhere-backed session store using sqlanydb sync sessions.
Methods:
| Name | Description |
|---|---|
create_table |
Create the session table if it doesn't exist. |
get |
Get a session value by key. |
set |
Store a session value. |
delete |
Delete a session by key. |
delete_all |
Delete all sessions from the store. |
exists |
Check if a session key exists and is not expired. |
expires_in |
Get the time in seconds until the session expires. |
delete_expired |
Delete all expired sessions. |
SqlanywhereADKStore
¶
SqlanywhereADKStore(config: SqlanywhereConfig)
Bases: BaseSyncADKStore['SqlanywhereConfig']
Synchronous SAP SQL Anywhere ADK session/event store.
Methods:
| Name | Description |
|---|---|
create_tables |
Create ADK tables and indexes using SQL Anywhere |
create_session |
Create a new ADK session. |
get_session |
Return a scoped session or |
update_session_state |
Replace a session's durable state. |
list_sessions |
List ADK sessions for an application, optionally scoped to a user. |
delete_session |
Delete a session and its associated events. |
append_event |
Append an event to a session. |
append_event_and_update_state |
Atomically append an event and update durable session/scoped state. |
get_events |
Return events for a scoped session ordered by event timestamp. |
delete_expired_events |
Delete events older than |
delete_idle_sessions |
Delete sessions whose update_time is older than |
delete_idle_user_states |
Delete user state rows whose update_time is older than |
get_app_state |
Return app-scoped state. |
get_user_state |
Return user-scoped state. |
upsert_app_state |
Insert or replace app-scoped state. |
upsert_user_state |
Insert or replace user-scoped state. |
get_metadata |
Return an ADK metadata value. |
set_metadata |
Set an ADK metadata value. |
Attributes:
| Name | Type | Description |
|---|---|---|
connector_name |
str
|
|
create_tables
¶
Create ADK tables and indexes using SQL Anywhere IF NOT EXISTS DDL.
create_session
¶
create_session(
session_id: str,
app_name: str,
user_id: str,
state: dict[str, Any],
owner_id: Any | None = None,
) -> StoredSession
Create a new ADK session.
get_session
¶
get_session(
app_name: str,
user_id: str,
session_id: str,
*,
renew_for: int | timedelta | None = None,
) -> StoredSession | None
Return a scoped session or None if absent.
update_session_state
¶
Replace a session's durable state.
list_sessions
¶
list_sessions(
app_name: str,
user_id: str | None = None,
*,
order_by: SessionOrderBy = "update_time",
descending: bool = True,
limit: int | None = None,
offset: int | None = None,
) -> list[StoredSession]
List ADK sessions for an application, optionally scoped to a user.
delete_session
¶
Delete a session and its associated events.
append_event_and_update_state
¶
append_event_and_update_state(
event_record: StoredEvent,
app_name: str,
user_id: str,
session_id: str,
state: dict[str, Any],
*,
app_state: dict[str, Any] | None = None,
user_state: dict[str, Any] | None = None,
) -> StoredSession
Atomically append an event and update durable session/scoped state.
get_events
¶
get_events(
app_name: str,
user_id: str,
session_id: str,
after_timestamp: datetime | None = None,
limit: int | None = None,
) -> list[StoredEvent]
Return events for a scoped session ordered by event timestamp.
delete_expired_events
¶
Delete events older than before.
delete_idle_sessions
¶
Delete sessions whose update_time is older than updated_before.
delete_idle_user_states
¶
Delete user state rows whose update_time is older than updated_before.
get_user_state
¶
Return user-scoped state.
upsert_app_state
¶
Insert or replace app-scoped state.
upsert_user_state
¶
Insert or replace user-scoped state.
SqlanywhereADKMemoryStore
¶
SqlanywhereADKMemoryStore(config: SqlanywhereConfig)
Bases: BaseSyncADKMemoryStore['SqlanywhereConfig']
SAP SQL Anywhere ADK memory store using sqlanydb.
Methods:
| Name | Description |
|---|---|
create_tables |
Create the memory table and indexes using SQL Anywhere |
insert_memory_entries |
Bulk insert memory entries with event-id deduplication. |
search_entries |
Search memory entries by text query. |
delete_entries_by_session |
Delete all memory entries for a specific session. |
delete_entries_older_than |
Delete memory entries older than the retention window. |
create_tables
¶
Create the memory table and indexes using SQL Anywhere IF NOT EXISTS DDL.
insert_memory_entries
¶
insert_memory_entries(
entries: list[StoredMemory], owner_id: object | None = None
) -> int
Bulk insert memory entries with event-id deduplication.
search_entries
¶
search_entries(
query: str,
app_name: str,
user_id: str,
limit: int | None = None,
scope_filter: Literal["all", "user", "app"] = "all",
embedding: Sequence[float] | None = None,
) -> list[StoredMemory]
Search memory entries by text query.
delete_entries_by_session
¶
Delete all memory entries for a specific session.
delete_entries_older_than
¶
delete_entries_older_than(
days: int, app_name: str | None = None, scope: str | None = None
) -> int
Delete memory entries older than the retention window.