from typing import TypeVar import logging from collections import namedtuple from .registry import Registry from .connector import Connector logger = logging.getLogger(__name__) T = TypeVar('T', bound=Registry) class Database(Connector): # cursor_factory = AsyncLoggingCursor def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.registries: dict[str, Registry] = {} def load_registry(self, registry: T) -> T: logger.debug( f"Loading and binding registry '{registry.name}'.", extra={'action': f"Reg {registry.name}"} ) registry.bind(self) self.registries[registry.name] = registry return registry