diff --git a/royalnet/__main__.py b/royalnet/__main__.py index 726c8b42..9d6543a8 100644 --- a/royalnet/__main__.py +++ b/royalnet/__main__.py @@ -156,9 +156,17 @@ def run(telegram: typing.Optional[bool], webserver_process: typing.Optional[multiprocessing.Process] = None if interfaces["webserver"]: + # Common tables are always included + constellation_tables = set(r.packs.common.available_tables) + # Find the required tables + for star in [*enabled_page_stars, *enabled_exception_stars]: + constellation_tables = constellation_tables.union(star.tables) + # Create the Constellation constellation = r.web.Constellation(page_stars=enabled_page_stars, exc_stars=enabled_exception_stars, - secrets_name=secrets_name) + secrets_name=secrets_name, + database_uri=database, + tables=constellation_tables) webserver_process = multiprocessing.Process(name="Constellation Webserver", target=constellation.run_blocking, args=(verbose,), diff --git a/royalnet/web/constellation.py b/royalnet/web/constellation.py index b26fdfa8..66e6c7a1 100644 --- a/royalnet/web/constellation.py +++ b/royalnet/web/constellation.py @@ -14,6 +14,8 @@ log = logging.getLogger(__name__) class Constellation: def __init__(self, secrets_name: str, + database_uri: str, + tables: set, page_stars: typing.List[typing.Type[PageStar]] = None, exc_stars: typing.List[typing.Type[ExceptionStar]] = None, *, @@ -29,6 +31,9 @@ class Constellation: log.info("Creating starlette app...") self.starlette = Starlette(debug=debug) + log.info(f"Creating alchemy with tables: {' '.join([table.__name__ for table in tables])}") + self.alchemy: royalnet.database.Alchemy = royalnet.database.Alchemy(database_uri=database_uri, tables=tables) + log.info("Registering page_stars...") for SelectedPageStar in page_stars: try: diff --git a/royalnet/web/star.py b/royalnet/web/star.py index 8e8c00bb..265594f0 100644 --- a/royalnet/web/star.py +++ b/royalnet/web/star.py @@ -14,6 +14,18 @@ class Star: async def page(self, request: Request, **kwargs) -> Response: raise NotImplementedError() + @property + def alchemy(self): + return self.constellation.alchemy + + @property + def Session(self): + return self.constellation.alchemy.Session + + @property + def session_acm(self): + return self.constellation.alchemy.session_acm + class PageStar(Star): path: str = NotImplemented