From 5ec27e934482e0d3b695f04eecf310e2cc6dca61 Mon Sep 17 00:00:00 2001 From: evilchili Date: Sat, 20 Apr 2024 23:40:17 -0700 Subject: [PATCH] default attributes on db object are now queries --- src/ttfrog/db/manager.py | 5 +---- test/test_schema.py | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ttfrog/db/manager.py b/src/ttfrog/db/manager.py index 4c349be..f2f1f56 100644 --- a/src/ttfrog/db/manager.py +++ b/src/ttfrog/db/manager.py @@ -85,10 +85,7 @@ class SQLDatabaseManager: return json.dumps(results, indent=2, cls=AlchemyEncoder) def __getattr__(self, name: str): - try: - return self.tables[name] - except KeyError: - raise AttributeError(f"{self} does not contain the attribute '{name}'.") + return self.query(getattr(ttfrog.db.schema, name)) db = SQLDatabaseManager() diff --git a/test/test_schema.py b/test/test_schema.py index a228373..7fc8ab8 100644 --- a/test/test_schema.py +++ b/test/test_schema.py @@ -8,7 +8,7 @@ def test_manage_character(db, classes_factory, ancestries_factory): # load the fixtures so they are bound to the current session classes = classes_factory() ancestries = ancestries_factory() - darkvision = db.session.query(schema.AncestryTrait).filter_by(name="Darkvision")[0] + darkvision = db.AncestryTrait.filter_by(name="Darkvision")[0] # create a human character (the default) char = schema.Character(name="Test Character")