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:
-
get_db_service_from–Get the database service from various source types.
-
get_db_controller_from–Get the database coordinator from various source types.
-
create_enhanced_controller_from–Create an enhanced BaseController instance from various source types.
Classes¶
Functions¶
_resolve_bot ¶
_resolve_bot(source: Context[Tux] | Interaction | Tux) -> Tux | None
Resolve the bot instance from various source types.
Parameters:
-
source(Context[Tux] | Interaction | Tux) –The source object to resolve the bot from.
Returns:
-
Tux | None–The resolved bot instance, or None if resolution fails.
get_db_service_from ¶
get_db_service_from(source: Context[Tux] | Interaction | Tux) -> DatabaseService | None
Get the database service from various source types.
Parameters:
-
source(Context[Tux] | Interaction | Tux) –The source object to get the database service from.
Returns:
-
DatabaseService | None–The database service instance, or None if not available.
get_db_controller_from ¶
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 ¶
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.