Skip to content

✨ [FEAT] add sql dependency example to docs #72

Description

@renardeinside

Need to document usage of dbsql:

def get_connection(
    app_config: Dependency.Config, user_ws: Dependency.UserClient
) -> Generator[Connection, None, None]:
    """
    Returns a connection to the warehouse.
    """
    with sql.connect(
        http_path=app_config.warehouse_http_path,
        server_hostname=user_ws.config.hostname,
        credentials_provider=lambda: user_ws.config.authenticate,
    ) as connection:
        yield connection


class Dependency:
    """FastAPI dependency injection shorthand for route handler parameters."""

    Client: TypeAlias = Annotated[WorkspaceClient, Depends(get_ws)]
    """Databricks WorkspaceClient using app-level service principal credentials.
    Recommended usage: `ws: Dependency.Client`"""

    UserClient: TypeAlias = Annotated[WorkspaceClient, Depends(get_user_ws)]
    """WorkspaceClient authenticated on behalf of the current user via OBO token.
    Requires the X-Forwarded-Access-Token header.
    Recommended usage: `user_ws: Dependency.UserClient`"""

    Config: TypeAlias = Annotated[AppConfig, Depends(get_config)]
    """Application configuration loaded from environment variables.
    Recommended usage: `config: Dependency.Config`"""

    UserConnection: TypeAlias = Annotated[Connection, Depends(get_connection)]
    """Connection to the warehouse.
    Recommended usage: `connection: Dependency.Connection`"""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions