Skip to content

Registry

deep_db_agents.registry

Global registry mapping URL scheme -> dialect class.

available_schemes

available_schemes() -> list[str]

List the schemes currently registered.

Returns:

Type Description
list[str]

list[str]: The list of registered scheme names.

Source code in src/deep_db_agents/registry.py
69
70
71
72
73
74
75
def available_schemes() -> list[str]:
    """List the schemes currently registered.

    Returns:
        list[str]: The list of registered scheme names.
    """
    return list(_REGISTRY)

register

register(*schemes: str)

Return a decorator that registers a DbDialect class for one or more URL schemes.

Parameters:

Name Type Description Default
*schemes str

URL scheme names to register the class under. If omitted, the class's own schemes attribute is used instead.

()

Returns:

Type Description

Callable[[type[DbDialect]], type[DbDialect]]: A decorator that registers the

decorated class and returns it unchanged.

Examples:

>>> @register("postgres", "postgresql")
... class PostgresDialect(DbDialect): ...
Source code in src/deep_db_agents/registry.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def register(*schemes: str):
    """Return a decorator that registers a ``DbDialect`` class for one or more URL schemes.

    Args:
        *schemes: URL scheme names to register the class under. If omitted, the
            class's own ``schemes`` attribute is used instead.

    Returns:
        Callable[[type[DbDialect]], type[DbDialect]]: A decorator that registers the
        decorated class and returns it unchanged.

    Examples:
        >>> @register("postgres", "postgresql")
        ... class PostgresDialect(DbDialect): ...
    """

    def decorator(cls: type[DbDialect]) -> type[DbDialect]:
        """Register ``cls`` under the enclosing ``schemes`` and return it.

        Args:
            cls: The dialect class to register.

        Returns:
            type[DbDialect]: The same class, unchanged.

        Raises:
            ValueError: If no scheme names are available (neither passed to
                :func:`register` nor set on ``cls.schemes``).
        """
        names = schemes or cls.schemes
        if not names:
            raise ValueError(f"{cls.__name__} does not specify any scheme to register.")
        cls.schemes = tuple(names)
        for scheme in names:
            _REGISTRY[scheme.lower()] = cls
        return cls

    return decorator

resolve

resolve(scheme: str) -> type[DbDialect]

Return the dialect class for a scheme.

Parameters:

Name Type Description Default
scheme str

The URL scheme to resolve (case-insensitive).

required

Returns:

Type Description
type[DbDialect]

type[DbDialect]: The dialect class registered for scheme.

Raises:

Type Description
UnsupportedSchemeError

If no dialect is registered for scheme.

Source code in src/deep_db_agents/registry.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def resolve(scheme: str) -> type[DbDialect]:
    """Return the dialect class for a scheme.

    Args:
        scheme: The URL scheme to resolve (case-insensitive).

    Returns:
        type[DbDialect]: The dialect class registered for ``scheme``.

    Raises:
        UnsupportedSchemeError: If no dialect is registered for ``scheme``.
    """
    try:
        return _REGISTRY[scheme.lower()]
    except KeyError:
        raise UnsupportedSchemeError(scheme, available_schemes()) from None