Source code for sqlspec.adapters.pymssql.config

"""pymssql database configuration."""

from collections.abc import Callable, Mapping
from typing import TYPE_CHECKING, Any, ClassVar, Literal, TypedDict, cast

from typing_extensions import NotRequired

from sqlspec.adapters.pymssql._typing import PymssqlConnection, PymssqlCursor, PymssqlRawCursor, PymssqlSessionContext
from sqlspec.adapters.pymssql.core import apply_driver_features, default_statement_config
from sqlspec.adapters.pymssql.driver import PymssqlDriver, PymssqlExceptionHandler
from sqlspec.adapters.pymssql.migrations import PymssqlSyncMigrationTracker
from sqlspec.adapters.pymssql.pool import PymssqlConnectionPool
from sqlspec.config import ExtensionConfigs, SyncDatabaseConfig
from sqlspec.driver._sync import SyncPoolConnectionContext, SyncPoolSessionFactory
from sqlspec.extensions.events import EventRuntimeHints
from sqlspec.utils.config_tools import normalize_connection_config

if TYPE_CHECKING:
    from sqlspec.core import StatementConfig
    from sqlspec.observability import ObservabilityConfig

__all__ = ("PymssqlConfig", "PymssqlConnectionParams", "PymssqlDriverFeatures", "PymssqlPoolParams", "PymssqlTimeout")

PymssqlTimeout = int | float


class PymssqlConnectionParams(TypedDict):
    """pymssql connection parameters."""

    server: NotRequired[str]
    host: NotRequired[str]
    user: NotRequired[str]
    password: NotRequired[str]
    database: NotRequired[str]
    port: NotRequired[int | str]
    timeout: NotRequired[PymssqlTimeout]
    login_timeout: NotRequired[PymssqlTimeout]
    charset: NotRequired[str]
    as_dict: NotRequired[bool]
    appname: NotRequired[str]
    conn_properties: NotRequired[str]
    autocommit: NotRequired[bool]
    tds_version: NotRequired[str]
    use_datetime2: NotRequired[bool]
    arraysize: NotRequired[int]
    conv: NotRequired[Mapping[int | type[Any], Callable[..., Any]]]
    read_only: NotRequired[bool]
    pool_recycle_seconds: NotRequired[int]
    health_check_interval: NotRequired[float]
    extra: NotRequired["dict[str, Any]"]
class PymssqlPoolParams(PymssqlConnectionParams): """pymssql pool parameters.""" class PymssqlDriverFeatures(TypedDict): """pymssql driver feature flags. json_serializer: Custom JSON serializer function. Defaults to sqlspec.utils.serializers.to_json. json_deserializer: Custom JSON deserializer function. Defaults to sqlspec.utils.serializers.from_json. on_connection_create: Callback executed when a connection is created. Receives the raw pymssql connection for low-level driver configuration. Runs after connection creation. enable_events: Enable database event channel support. events_backend: Event channel backend selection. """ json_serializer: NotRequired["Callable[[Any], str]"] json_deserializer: NotRequired["Callable[[str], Any]"] on_connection_create: "NotRequired[Callable[[PymssqlConnection], None]]" enable_events: NotRequired[bool] events_backend: NotRequired[Literal["poll_queue"]]