Skip to content

utils

Database Utilities for Tux Bot.

This module provides utility functions for accessing database services, controllers, and coordinators from various Discord context sources like commands.Context, discord.Interaction, or Tux bot instances.

Functions:

Classes

Functions

_resolve_bot

Python
_resolve_bot(source: Context[Tux] | Interaction | Tux) -> Tux | None

Resolve the bot instance from various source types.

Parameters:

Returns:

  • Tux | None

    The resolved bot instance, or None if resolution fails.

get_db_service_from

Python
get_db_service_from(source: Context[Tux] | Interaction | Tux) -> DatabaseService | None

Get the database service from various source types.

Parameters:

Returns:

  • DatabaseService | None

    The database service instance, or None if not available.

get_db_controller_from

Python
get_db_controller_from(
    source: Context[Tux] | Interaction | Tux, *, fallback_to_direct: bool = True
) -> DatabaseCoordinator | None

Get the database coordinator from various source types.

Parameters:

  • source (Context[Tux] | Interaction | Tux) –

    The source object to get the database coordinator from.

  • fallback_to_direct (bool, default: True ) –

    Whether to fallback to creating a direct DatabaseCoordinator instance if the service-based approach fails, by default True.

Returns:

  • DatabaseCoordinator | None

    The database coordinator instance, or None if not available and fallback_to_direct is False.

create_enhanced_controller_from

Python
create_enhanced_controller_from[ModelT](
    source: Context[Tux] | Interaction | Tux, model: type[ModelT]
) -> BaseController[ModelT] | None

Create an enhanced BaseController instance from various source types.

This provides access to the new enhanced controller pattern with: - Sentry integration - Transaction management - Better error handling - Query performance monitoring

Parameters:

  • source (Context[Tux] | Interaction | Tux) –

    The source object to get the database service from.

  • model (type[ModelT]) –

    The SQLModel class to create a controller for.

Returns:

  • BaseController[ModelT] | None

    The enhanced controller instance, or None if not available.