from typing import TYPE_CHECKING, Any from .GameplayDatabase import GameplayDatabase from .backend import GameplayBackendBuilder if TYPE_CHECKING: from .EdgeDB import EdgeDB from .LocalStorage import LocalStorage __all__ = ( "EdgeDB", "GameplayBackendBuilder", "GameplayDatabase", "LocalStorage", "StorageLoader", ) def __getattr__(name:str): """Load optional storage backends only when explicitly requested. Database maintenance scripts import SQLite backend modules through this package. Eagerly importing LocalStorage used to make those scripts require unrelated web-storage dependencies such as aiofiles. """ if name == "LocalStorage": from .LocalStorage import LocalStorage return LocalStorage if name == "EdgeDB": from .EdgeDB import EdgeDB return EdgeDB raise AttributeError(f"module {__name__!r} has no attribute {name!r}") class StorageLoader: @classmethod def build(cls, selected_storage:str) -> Any: storage_module = __import__( f"server.database.{selected_storage}", fromlist=[selected_storage], ) storage_class = getattr(storage_module, selected_storage) return storage_class