renus 3.2.0__tar.gz → 3.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {renus-3.2.0/renus.egg-info → renus-3.2.1}/PKG-INFO +1 -1
- {renus-3.2.0 → renus-3.2.1}/renus/__init__.py +1 -1
- {renus-3.2.0 → renus-3.2.1}/renus/commands/app/temp.py +2 -5
- {renus-3.2.0 → renus-3.2.1}/renus/db/models/base.py +57 -39
- {renus-3.2.0 → renus-3.2.1}/renus/db/mongodb/compiler.py +46 -6
- {renus-3.2.0 → renus-3.2.1}/renus/db/mysql/adapter.py +1 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/adapter.py +22 -1
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/compiler/compiler.py +78 -11
- {renus-3.2.0 → renus-3.2.1}/renus/schedule/schedule.py +14 -18
- {renus-3.2.0 → renus-3.2.1}/renus/schedule/state.py +1 -4
- {renus-3.2.0 → renus-3.2.1}/renus/util/serialization.py +3 -0
- {renus-3.2.0 → renus-3.2.1/renus.egg-info}/PKG-INFO +1 -1
- {renus-3.2.0 → renus-3.2.1}/tests/test_schedule.py +29 -4
- {renus-3.2.0 → renus-3.2.1}/LICENSE +0 -0
- {renus-3.2.0 → renus-3.2.1}/MANIFEST.in +0 -0
- {renus-3.2.0 → renus-3.2.1}/README.md +0 -0
- {renus-3.2.0 → renus-3.2.1}/pyproject.toml +0 -0
- {renus-3.2.0 → renus-3.2.1}/pytest.ini +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/__main__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/_speedup.c +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/_speedup.pyx +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/app/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/app/app.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/app/dispatch.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/app/handlers.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/app/lifespan.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/base.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/cache.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/file.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/redis.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/signing.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/cache/utils.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/app/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/app/run.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/base.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/cli.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/create/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/create/local_run_template.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/create/run.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/db/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/db/run.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/extension/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/extension/build.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/extension/remove.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/extension/run.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/help.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/routing.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/run/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/commands/run/run.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/config/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/config/config.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/datastructures/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/datastructures/background.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/datastructures/id.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/datastructures/multidict.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/datastructures/uploads.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/adapter.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/backup.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/convert.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/events.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/exceptions.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/core/state.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/database.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/errors.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/metadata/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/metadata/core.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/metadata/inference.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/migrations/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/migrations/exceptions.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/migrations/manager.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/migrations/operations.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/migrations/tracker.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/models/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/models/db_field.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/models/field.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mongodb/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mongodb/adapter.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mongodb/dialect.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mutation/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mutation/ast.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mysql/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/mysql/dialect.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/plugins/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/plugins/core.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/plugins/registry.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/query/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/query/ast.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/query/builder.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/relationships.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/repository/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/repository/core.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/repository/normalize.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/repository/relationships.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/serialization/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/serialization/core.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/compiler/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/dialect/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/dialect/base.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sql/mutation.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sqlite/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sqlite/adapter.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/sqlite/dialect.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/transaction/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/transaction/core.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/validation/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/validation/base.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/validation/engine.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/db/validation/rules.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/log/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/log/formatters.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/log/handlers.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/log/logger.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/exceptions.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/formparsers.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/injection.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/limits.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/options.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/parsers.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/request.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/request/xss.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/base.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/exceptions.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/file.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/gzip.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/json.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/private.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/redirects.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/status.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/streaming.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/response/text.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/_style.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/header.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/markdown.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/progress.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/style_context.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/table.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/rich/terminal.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/chain.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/convertors.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/middleware.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/path.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/registry.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/router/router.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/schedule/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/schedule/matcher.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/schedule/runner.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/codec.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/concurrency.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/naming.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/random.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/security.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/util/version.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/websockets/__init__.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/websockets/messages.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/websockets/protocol.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/websockets/session.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus/websockets/state.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus.egg-info/SOURCES.txt +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus.egg-info/dependency_links.txt +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus.egg-info/entry_points.txt +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus.egg-info/requires.txt +0 -0
- {renus-3.2.0 → renus-3.2.1}/renus.egg-info/top_level.txt +0 -0
- {renus-3.2.0 → renus-3.2.1}/setup.cfg +0 -0
- {renus-3.2.0 → renus-3.2.1}/setup.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_app.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_cache.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_commands.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_concurrency.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_config.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_datastructures.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_log.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_request.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_response.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_rich.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_routing.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_util.py +0 -0
- {renus-3.2.0 → renus-3.2.1}/tests/test_websockets.py +0 -0
|
@@ -43,9 +43,6 @@ from renus.db.validation import MaxLen
|
|
|
43
43
|
from renus.datastructures import ID
|
|
44
44
|
|
|
45
45
|
class {name_camel}(Model):
|
|
46
|
-
"""Domain model for {name}.
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
46
|
id: ID = Field(default_factory=ID,database=DatabaseField(primary_key=True,generated=True))
|
|
50
47
|
|
|
51
48
|
# --- Example fields; customize for your domain. ---
|
|
@@ -92,8 +89,8 @@ admin_router.put("/{names}/{id:id}", {name_camel}Controller, "update", middlewar
|
|
|
92
89
|
admin_router.delete("/{names}/{id:id}", {name_camel}Controller, "delete", middlewares=[PermissionMiddleware("{names}.delete")])
|
|
93
90
|
{soft_delete_kit_routes}
|
|
94
91
|
|
|
95
|
-
user_router = Router(prefix="/user", middlewares=[AuthMiddleware])
|
|
96
|
-
home_router = Router(prefix="/home")
|
|
92
|
+
user_router = Router(prefix="/api/user", middlewares=[AuthMiddleware])
|
|
93
|
+
home_router = Router(prefix="/api/home")
|
|
97
94
|
router = Router()
|
|
98
95
|
router.include(admin_router)
|
|
99
96
|
router.include(user_router)
|
|
@@ -4,6 +4,7 @@ import copy
|
|
|
4
4
|
from datetime import date, datetime, timezone
|
|
5
5
|
from typing import Any, ClassVar, dataclass_transform, get_origin
|
|
6
6
|
|
|
7
|
+
from renus.datastructures.id import ID
|
|
7
8
|
from renus.db.core.exceptions import ValidationError
|
|
8
9
|
from renus.db.core.state import IdentityKind, Lifecycle
|
|
9
10
|
from renus.db.metadata.core import (
|
|
@@ -15,15 +16,14 @@ from renus.db.metadata.core import (
|
|
|
15
16
|
)
|
|
16
17
|
from renus.db.metadata.inference import analyze_field_type, infer_identity_kind
|
|
17
18
|
from renus.db.models.db_field import UNSET, DatabaseField
|
|
18
|
-
from renus.db.models.field import Field, FieldInfo
|
|
19
|
-
from renus.db.validation.base import Rule
|
|
20
|
-
from renus.datastructures.id import ID
|
|
19
|
+
from renus.db.models.field import _UNSET, Field, FieldInfo
|
|
21
20
|
from renus.db.query.ast import Path
|
|
22
21
|
from renus.db.relationships import Relationship
|
|
23
|
-
|
|
22
|
+
from renus.db.validation.base import Rule
|
|
24
23
|
|
|
25
24
|
_MODEL_REGISTRY: dict[str, type] = {}
|
|
26
25
|
|
|
26
|
+
|
|
27
27
|
class ModelMeta(type):
|
|
28
28
|
"""Metaclass that builds model metadata and field definitions."""
|
|
29
29
|
|
|
@@ -54,12 +54,14 @@ class ModelMeta(type):
|
|
|
54
54
|
ns[key] = Field(default=default_val, database=val)
|
|
55
55
|
elif isinstance(val, Field):
|
|
56
56
|
extra = getattr(val, "extra", {}) or {}
|
|
57
|
-
db =
|
|
57
|
+
db = (
|
|
58
|
+
getattr(val, "database", None)
|
|
59
|
+
or extra.get("database")
|
|
60
|
+
or extra.get("db")
|
|
61
|
+
)
|
|
58
62
|
if isinstance(db, DatabaseField):
|
|
59
63
|
declared_db_fields[key] = db
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
65
|
meta_cls = ns.get("Meta")
|
|
64
66
|
timestamps = bool(getattr(meta_cls, "timestamps", False))
|
|
65
67
|
soft_delete = bool(getattr(meta_cls, "soft_delete", False))
|
|
@@ -78,7 +80,9 @@ class ModelMeta(type):
|
|
|
78
80
|
if timestamps:
|
|
79
81
|
if "created_at" not in annotations:
|
|
80
82
|
annotations["created_at"] = datetime | None
|
|
81
|
-
ns["created_at"] = Field(
|
|
83
|
+
ns["created_at"] = Field(
|
|
84
|
+
default=None, database=DatabaseField(indexed=True)
|
|
85
|
+
)
|
|
82
86
|
if "updated_at" not in annotations:
|
|
83
87
|
annotations["updated_at"] = datetime | None
|
|
84
88
|
ns["updated_at"] = Field(default=None)
|
|
@@ -89,7 +93,9 @@ class ModelMeta(type):
|
|
|
89
93
|
ns["deleted_at"] = Field(default=None)
|
|
90
94
|
if "is_deleted" not in annotations:
|
|
91
95
|
annotations["is_deleted"] = bool
|
|
92
|
-
ns["is_deleted"] = Field(
|
|
96
|
+
ns["is_deleted"] = Field(
|
|
97
|
+
default=False, database=DatabaseField(indexed=True)
|
|
98
|
+
)
|
|
93
99
|
|
|
94
100
|
ns["__annotations__"] = annotations
|
|
95
101
|
|
|
@@ -100,7 +106,6 @@ class ModelMeta(type):
|
|
|
100
106
|
|
|
101
107
|
table = getattr(meta_cls, "table", None)
|
|
102
108
|
if not table:
|
|
103
|
-
|
|
104
109
|
table = f"{name.lower()}s"
|
|
105
110
|
|
|
106
111
|
all_relationships: dict[str, Relationship] = {}
|
|
@@ -110,7 +115,6 @@ class ModelMeta(type):
|
|
|
110
115
|
all_relationships[k] = v
|
|
111
116
|
all_relationships.update(declared_relationships)
|
|
112
117
|
|
|
113
|
-
|
|
114
118
|
validation_fields: dict[str, FieldInfo] = getattr(cls, "_model_fields", {})
|
|
115
119
|
for rname, rel in all_relationships.items():
|
|
116
120
|
rel.__set_name__(cls, rname)
|
|
@@ -176,9 +180,10 @@ class ModelMeta(type):
|
|
|
176
180
|
)
|
|
177
181
|
col_name = db.column_name or fname
|
|
178
182
|
|
|
179
|
-
pk = db.primary_key or (
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
pk = db.primary_key or (
|
|
184
|
+
fname in ("id", "_id")
|
|
185
|
+
and not any(d.primary_key for d in declared_db_fields.values())
|
|
186
|
+
)
|
|
182
187
|
|
|
183
188
|
if db.auto_inc and not pk:
|
|
184
189
|
raise ValueError(
|
|
@@ -278,7 +283,6 @@ class ModelMeta(type):
|
|
|
278
283
|
generated=pk_meta.generated,
|
|
279
284
|
)
|
|
280
285
|
else:
|
|
281
|
-
|
|
282
286
|
if "_id" in fields_dict:
|
|
283
287
|
pk_meta = fields_dict["_id"]
|
|
284
288
|
object.__setattr__(pk_meta, "primary_key", True)
|
|
@@ -299,7 +303,6 @@ class ModelMeta(type):
|
|
|
299
303
|
generated=pk_meta.generated,
|
|
300
304
|
)
|
|
301
305
|
else:
|
|
302
|
-
|
|
303
306
|
default_db = DatabaseField(primary_key=True, generated=True)
|
|
304
307
|
id_meta = FieldMetadata(
|
|
305
308
|
name="id",
|
|
@@ -345,9 +348,13 @@ class ModelMeta(type):
|
|
|
345
348
|
|
|
346
349
|
for fname, fmeta in fields_dict.items():
|
|
347
350
|
if fmeta.unique:
|
|
348
|
-
indexes.append(
|
|
351
|
+
indexes.append(
|
|
352
|
+
Index(fmeta.column_name, unique=True, name=fmeta.index_name)
|
|
353
|
+
)
|
|
349
354
|
elif fmeta.indexed:
|
|
350
|
-
indexes.append(
|
|
355
|
+
indexes.append(
|
|
356
|
+
Index(fmeta.column_name, unique=False, name=fmeta.index_name)
|
|
357
|
+
)
|
|
351
358
|
|
|
352
359
|
meta_indexes = getattr(meta_cls, "indexes", ())
|
|
353
360
|
if isinstance(meta_indexes, (list, tuple)):
|
|
@@ -355,7 +362,6 @@ class ModelMeta(type):
|
|
|
355
362
|
if isinstance(idx, Index):
|
|
356
363
|
indexes.append(idx)
|
|
357
364
|
|
|
358
|
-
|
|
359
365
|
model_meta = ModelMetadata(
|
|
360
366
|
model=cls,
|
|
361
367
|
table=table,
|
|
@@ -376,6 +382,7 @@ class ModelMeta(type):
|
|
|
376
382
|
|
|
377
383
|
return cls
|
|
378
384
|
|
|
385
|
+
|
|
379
386
|
@dataclass_transform(
|
|
380
387
|
field_specifiers=(Field, DatabaseField, Relationship),
|
|
381
388
|
kw_only_default=True,
|
|
@@ -406,8 +413,7 @@ class Model(metaclass=ModelMeta):
|
|
|
406
413
|
if name.startswith("_"):
|
|
407
414
|
continue
|
|
408
415
|
if get_origin(field_type) is ClassVar or (
|
|
409
|
-
isinstance(field_type, str)
|
|
410
|
-
and field_type.startswith("ClassVar[")
|
|
416
|
+
isinstance(field_type, str) and field_type.startswith("ClassVar[")
|
|
411
417
|
):
|
|
412
418
|
continue
|
|
413
419
|
|
|
@@ -432,7 +438,6 @@ class Model(metaclass=ModelMeta):
|
|
|
432
438
|
|
|
433
439
|
cls._model_fields = fields
|
|
434
440
|
|
|
435
|
-
|
|
436
441
|
@classmethod
|
|
437
442
|
def schema(cls) -> dict[str, Any]:
|
|
438
443
|
"""Return a JSON Schema for the model.
|
|
@@ -533,7 +538,6 @@ class Model(metaclass=ModelMeta):
|
|
|
533
538
|
elif field_type in (Any, object):
|
|
534
539
|
continue
|
|
535
540
|
else:
|
|
536
|
-
|
|
537
541
|
# Custom runtime types need an explicit schema rule or a
|
|
538
542
|
# custom Model schema implementation.
|
|
539
543
|
continue
|
|
@@ -563,7 +567,9 @@ class Model(metaclass=ModelMeta):
|
|
|
563
567
|
result = add_nullable(result)
|
|
564
568
|
return result
|
|
565
569
|
|
|
566
|
-
def relationship_schema(
|
|
570
|
+
def relationship_schema(
|
|
571
|
+
rel: RelationshipMetadata, stack: set[type]
|
|
572
|
+
) -> dict[str, Any]:
|
|
567
573
|
target = rel.target
|
|
568
574
|
if target is dict:
|
|
569
575
|
result: dict[str, Any] = {"type": "object"}
|
|
@@ -603,7 +609,6 @@ class Model(metaclass=ModelMeta):
|
|
|
603
609
|
):
|
|
604
610
|
required.append(name)
|
|
605
611
|
|
|
606
|
-
|
|
607
612
|
result: dict[str, Any] = {
|
|
608
613
|
"title": model.__name__,
|
|
609
614
|
"type": "object",
|
|
@@ -632,7 +637,11 @@ class Model(metaclass=ModelMeta):
|
|
|
632
637
|
|
|
633
638
|
@staticmethod
|
|
634
639
|
def _is_model_type(field_type: Any) -> bool:
|
|
635
|
-
return
|
|
640
|
+
return (
|
|
641
|
+
bool(field_type)
|
|
642
|
+
and isinstance(field_type, type)
|
|
643
|
+
and issubclass(field_type, Model)
|
|
644
|
+
)
|
|
636
645
|
|
|
637
646
|
@classmethod
|
|
638
647
|
def _dump_value(cls, val: Any) -> Any:
|
|
@@ -646,7 +655,6 @@ class Model(metaclass=ModelMeta):
|
|
|
646
655
|
return {k: cls._dump_value(v) for k, v in val.items()}
|
|
647
656
|
return val
|
|
648
657
|
|
|
649
|
-
|
|
650
658
|
def get_sensitive(self, name: str) -> Any:
|
|
651
659
|
"""Return a field's raw value, bypassing sensitive masking."""
|
|
652
660
|
if name == "is_deleted":
|
|
@@ -671,7 +679,9 @@ class Model(metaclass=ModelMeta):
|
|
|
671
679
|
def __iter__(self):
|
|
672
680
|
keys = list(self._model_fields.keys())
|
|
673
681
|
for k in self.__dict__:
|
|
674
|
-
if (not k.startswith("_") and k not in keys) or (
|
|
682
|
+
if (not k.startswith("_") and k not in keys) or (
|
|
683
|
+
k == "_id" and k not in keys
|
|
684
|
+
):
|
|
675
685
|
keys.append(k)
|
|
676
686
|
|
|
677
687
|
meta = self.__db_metadata__
|
|
@@ -734,10 +744,11 @@ class Model(metaclass=ModelMeta):
|
|
|
734
744
|
meta = getattr(self.__class__, "__db_metadata__", None)
|
|
735
745
|
|
|
736
746
|
try:
|
|
737
|
-
|
|
738
747
|
object.__setattr__(self, "_initialized", False)
|
|
739
748
|
|
|
740
|
-
if not self._model_fields and getattr(
|
|
749
|
+
if not self._model_fields and getattr(
|
|
750
|
+
self.__class__, "__annotations__", None
|
|
751
|
+
):
|
|
741
752
|
self.__class__._setup_model_fields()
|
|
742
753
|
|
|
743
754
|
data: dict[str, Any] = {}
|
|
@@ -751,7 +762,6 @@ class Model(metaclass=ModelMeta):
|
|
|
751
762
|
if kwargs:
|
|
752
763
|
data.update(kwargs)
|
|
753
764
|
|
|
754
|
-
|
|
755
765
|
errors: dict[str, list[Any]] = {}
|
|
756
766
|
values: dict[str, Any] = {}
|
|
757
767
|
|
|
@@ -771,7 +781,9 @@ class Model(metaclass=ModelMeta):
|
|
|
771
781
|
else:
|
|
772
782
|
val = raw_val
|
|
773
783
|
|
|
774
|
-
cleaned_val, field_errors = field_info.clean_and_validate(
|
|
784
|
+
cleaned_val, field_errors = field_info.clean_and_validate(
|
|
785
|
+
val, self.__class__
|
|
786
|
+
)
|
|
775
787
|
if field_errors:
|
|
776
788
|
errors[name] = field_errors
|
|
777
789
|
else:
|
|
@@ -806,7 +818,6 @@ class Model(metaclass=ModelMeta):
|
|
|
806
818
|
raise
|
|
807
819
|
raise ValidationError(e.args or str(e)) from e
|
|
808
820
|
|
|
809
|
-
|
|
810
821
|
if meta and meta.timestamps:
|
|
811
822
|
now = datetime.now(timezone.utc)
|
|
812
823
|
if getattr(self, "created_at", None) is None:
|
|
@@ -864,7 +875,9 @@ class Model(metaclass=ModelMeta):
|
|
|
864
875
|
try:
|
|
865
876
|
if name in self._model_fields:
|
|
866
877
|
field_info = self._model_fields[name]
|
|
867
|
-
cleaned_val, field_errors = field_info.clean_and_validate(
|
|
878
|
+
cleaned_val, field_errors = field_info.clean_and_validate(
|
|
879
|
+
value, self.__class__
|
|
880
|
+
)
|
|
868
881
|
if field_errors:
|
|
869
882
|
raise ValidationError({name: field_errors})
|
|
870
883
|
if name == "is_deleted":
|
|
@@ -887,14 +900,17 @@ class Model(metaclass=ModelMeta):
|
|
|
887
900
|
if is_relationship or self._is_field_dirty(name):
|
|
888
901
|
object.__setattr__(self, "_db_state", Lifecycle.DIRTY)
|
|
889
902
|
else:
|
|
890
|
-
|
|
891
903
|
if not self._any_field_dirty():
|
|
892
904
|
object.__setattr__(self, "_db_state", Lifecycle.PERSISTED)
|
|
893
905
|
else:
|
|
894
906
|
object.__setattr__(self, name, value)
|
|
895
907
|
|
|
896
908
|
def _is_field_dirty(self, name: str) -> bool:
|
|
897
|
-
current =
|
|
909
|
+
current = (
|
|
910
|
+
self.get_sensitive(name)
|
|
911
|
+
if name == "is_deleted"
|
|
912
|
+
else self.__dict__.get(name)
|
|
913
|
+
)
|
|
898
914
|
original = self._db_original_snapshot.get(name)
|
|
899
915
|
return current != original
|
|
900
916
|
|
|
@@ -949,7 +965,11 @@ class Model(metaclass=ModelMeta):
|
|
|
949
965
|
changes: dict[str, tuple[Any, Any]] = {}
|
|
950
966
|
for fname in self.get_dirty_fields():
|
|
951
967
|
original = self._db_original_snapshot.get(fname)
|
|
952
|
-
current =
|
|
968
|
+
current = (
|
|
969
|
+
self.get_sensitive(fname)
|
|
970
|
+
if fname == "is_deleted"
|
|
971
|
+
else self.__dict__.get(fname)
|
|
972
|
+
)
|
|
953
973
|
changes[fname] = (original, current)
|
|
954
974
|
return changes
|
|
955
975
|
|
|
@@ -1002,9 +1022,7 @@ class Model(metaclass=ModelMeta):
|
|
|
1002
1022
|
meta = self.__db_metadata__
|
|
1003
1023
|
return {f: getattr(self, f, None) for f in meta.identity.fields}
|
|
1004
1024
|
|
|
1005
|
-
|
|
1006
1025
|
@classmethod
|
|
1007
1026
|
def metadata(cls) -> ModelMetadata:
|
|
1008
1027
|
"""Return the model's metadata object."""
|
|
1009
1028
|
return cls.__db_metadata__
|
|
1010
|
-
|
|
@@ -17,6 +17,7 @@ from renus.db.query.ast import (
|
|
|
17
17
|
LIKE_ESCAPE,
|
|
18
18
|
Condition,
|
|
19
19
|
HavingCondition,
|
|
20
|
+
Include,
|
|
20
21
|
Logical,
|
|
21
22
|
Operator,
|
|
22
23
|
Path,
|
|
@@ -314,10 +315,30 @@ class MongoCompiler:
|
|
|
314
315
|
pipeline.append({"$limit": ast.limit})
|
|
315
316
|
|
|
316
317
|
if ast.projection:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
project = {"_id": 0}
|
|
319
|
+
for path in ast.projection.paths:
|
|
320
|
+
if not path.parts:
|
|
321
|
+
continue
|
|
322
|
+
name = path.parts[-1]
|
|
323
|
+
if (
|
|
324
|
+
path.model is source
|
|
325
|
+
and len(path.parts) == 1
|
|
326
|
+
and meta is not None
|
|
327
|
+
and name in meta.relationships
|
|
328
|
+
):
|
|
329
|
+
project[name] = 1
|
|
330
|
+
elif (
|
|
331
|
+
path.model is source
|
|
332
|
+
and len(path.parts) == 1
|
|
333
|
+
and meta is not None
|
|
334
|
+
and name == meta.primary_key_field == "id"
|
|
335
|
+
):
|
|
336
|
+
project[name] = f"${self._path_str(path)}"
|
|
337
|
+
elif len(path.parts) > 1:
|
|
338
|
+
project[name] = f"${self._path_str(path)}"
|
|
339
|
+
else:
|
|
340
|
+
project[self._path_str(path)] = 1
|
|
341
|
+
pipeline.append({"$project": project})
|
|
321
342
|
return MongoCompiledQuery(
|
|
322
343
|
collection=collection_name,
|
|
323
344
|
filter_doc={},
|
|
@@ -548,12 +569,22 @@ class MongoCompiler:
|
|
|
548
569
|
ast: QueryAST,
|
|
549
570
|
) -> tuple[list[dict[str, Any]], list[str]]:
|
|
550
571
|
"""Build recursive relationship lookups in one aggregation pipeline."""
|
|
551
|
-
if ast.
|
|
572
|
+
if ast.aggregates:
|
|
552
573
|
return [], []
|
|
553
574
|
root_meta = getattr(ast.source, "__db_metadata__", None)
|
|
554
575
|
if root_meta is None:
|
|
555
576
|
return [], []
|
|
556
577
|
|
|
578
|
+
projected_relationships = tuple(
|
|
579
|
+
dict.fromkeys(
|
|
580
|
+
path.parts[0]
|
|
581
|
+
for path in (ast.projection.paths if ast.projection else ())
|
|
582
|
+
if path.model is ast.source
|
|
583
|
+
and len(path.parts) == 1
|
|
584
|
+
and path.parts[0] in root_meta.relationships
|
|
585
|
+
)
|
|
586
|
+
)
|
|
587
|
+
projected_relationship_names = set(projected_relationships)
|
|
557
588
|
requested: dict[tuple[str, ...], Any] = {}
|
|
558
589
|
|
|
559
590
|
def collect(item: Any, prefix: tuple[str, ...] = ()) -> None:
|
|
@@ -563,7 +594,14 @@ class MongoCompiler:
|
|
|
563
594
|
collect(nested, path)
|
|
564
595
|
|
|
565
596
|
for item in ast.includes:
|
|
597
|
+
if ast.projection and (
|
|
598
|
+
not item.path.parts
|
|
599
|
+
or item.path.parts[0] not in projected_relationship_names
|
|
600
|
+
):
|
|
601
|
+
continue
|
|
566
602
|
collect(item)
|
|
603
|
+
for name in projected_relationships:
|
|
604
|
+
requested.setdefault((name,), Include(Path(ast.source, (name,))))
|
|
567
605
|
|
|
568
606
|
def mongo_field(model_meta: Any, field_name: str) -> str:
|
|
569
607
|
return "_id" if field_name == model_meta.primary_key_field else field_name
|
|
@@ -578,7 +616,9 @@ class MongoCompiler:
|
|
|
578
616
|
direct.setdefault(remainder[0], include)
|
|
579
617
|
for name, rel in owner_meta.relationships.items():
|
|
580
618
|
loading = getattr(rel.loading, "value", rel.loading)
|
|
581
|
-
if loading == "joined"
|
|
619
|
+
if loading == "joined" and (
|
|
620
|
+
not ast.projection or prefix or name in projected_relationship_names
|
|
621
|
+
):
|
|
582
622
|
direct.setdefault(name, None)
|
|
583
623
|
|
|
584
624
|
stages: list[dict[str, Any]] = []
|
|
@@ -369,6 +369,7 @@ class MySQLAdapter(SQLAdapter):
|
|
|
369
369
|
joined=sql_compiled.joined,
|
|
370
370
|
root_limit=sql_compiled.root_limit,
|
|
371
371
|
root_offset=sql_compiled.root_offset,
|
|
372
|
+
projection_paths=sql_compiled.projection_paths,
|
|
372
373
|
)
|
|
373
374
|
|
|
374
375
|
cursor_cls = aiomysql.DictCursor if aiomysql is not None else None
|
|
@@ -118,6 +118,17 @@ class SQLAdapter(AsyncDatabaseAdapter):
|
|
|
118
118
|
root_meta = compiled.meta
|
|
119
119
|
root_pk = root_meta.get_field(root_meta.primary_key_field)
|
|
120
120
|
root_column = root_pk.column_name if root_pk else root_meta.primary_key_field
|
|
121
|
+
projection_paths = getattr(compiled, "projection_paths", ())
|
|
122
|
+
projected_relationships = tuple(
|
|
123
|
+
dict.fromkeys(
|
|
124
|
+
path.parts[0]
|
|
125
|
+
for path in projection_paths
|
|
126
|
+
if path.model is root_meta.model
|
|
127
|
+
and path.parts
|
|
128
|
+
and path.parts[0] in root_meta.relationships
|
|
129
|
+
)
|
|
130
|
+
)
|
|
131
|
+
projected_relationship_names = set(projected_relationships)
|
|
121
132
|
grouped: dict[Any, dict[str, Any]] = {}
|
|
122
133
|
child_keys: dict[tuple[Any, tuple[str, ...]], set[Any]] = {}
|
|
123
134
|
|
|
@@ -127,9 +138,12 @@ class SQLAdapter(AsyncDatabaseAdapter):
|
|
|
127
138
|
key: value
|
|
128
139
|
for key, value in row.items()
|
|
129
140
|
if not key.startswith("__renus_joined__")
|
|
141
|
+
and key != "__renus_root_pk"
|
|
130
142
|
}
|
|
131
143
|
root = self.decode_row(root_data, root_meta)
|
|
132
|
-
root_id =
|
|
144
|
+
root_id = row.get("__renus_root_pk")
|
|
145
|
+
if root_id is None:
|
|
146
|
+
root_id = root.get(root_meta.primary_key_field, root.get(root_column))
|
|
133
147
|
if root_id not in grouped:
|
|
134
148
|
grouped[root_id] = root
|
|
135
149
|
root = grouped[root_id]
|
|
@@ -174,6 +188,13 @@ class SQLAdapter(AsyncDatabaseAdapter):
|
|
|
174
188
|
)
|
|
175
189
|
|
|
176
190
|
result = list(grouped.values())
|
|
191
|
+
if projection_paths:
|
|
192
|
+
for root in result:
|
|
193
|
+
for name in projected_relationship_names:
|
|
194
|
+
root.setdefault(
|
|
195
|
+
name,
|
|
196
|
+
[] if root_meta.relationships[name].is_collection else None,
|
|
197
|
+
)
|
|
177
198
|
start = compiled.root_offset or 0
|
|
178
199
|
end = start + compiled.root_limit if compiled.root_limit is not None else None
|
|
179
200
|
return result[start:end]
|
|
@@ -34,7 +34,15 @@ _VALUE_OPERATORS = {
|
|
|
34
34
|
|
|
35
35
|
class SQLCompiled:
|
|
36
36
|
|
|
37
|
-
__slots__ = (
|
|
37
|
+
__slots__ = (
|
|
38
|
+
"joined",
|
|
39
|
+
"meta",
|
|
40
|
+
"params",
|
|
41
|
+
"projection_paths",
|
|
42
|
+
"root_limit",
|
|
43
|
+
"root_offset",
|
|
44
|
+
"sql",
|
|
45
|
+
)
|
|
38
46
|
|
|
39
47
|
def __init__(
|
|
40
48
|
self,
|
|
@@ -44,6 +52,7 @@ class SQLCompiled:
|
|
|
44
52
|
joined: tuple[dict[str, Any], ...] = (),
|
|
45
53
|
root_limit: int | None = None,
|
|
46
54
|
root_offset: int | None = None,
|
|
55
|
+
projection_paths: tuple[Path, ...] = (),
|
|
47
56
|
) -> None:
|
|
48
57
|
"""Hold a compiled SQL statement and its binding parameters.
|
|
49
58
|
|
|
@@ -62,6 +71,7 @@ class SQLCompiled:
|
|
|
62
71
|
self.joined = joined
|
|
63
72
|
self.root_limit = root_limit
|
|
64
73
|
self.root_offset = root_offset
|
|
74
|
+
self.projection_paths = projection_paths
|
|
65
75
|
|
|
66
76
|
def __repr__(self) -> str:
|
|
67
77
|
return f"SQLCompiled(sql={self.sql!r}, params={self.params!r})"
|
|
@@ -111,10 +121,44 @@ class SQLCompiler:
|
|
|
111
121
|
select_items.append(f"{fn_name}({distinct_agg}{target}) AS {alias}")
|
|
112
122
|
select_clause = ", ".join(select_items)
|
|
113
123
|
elif ast.projection:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for
|
|
117
|
-
|
|
124
|
+
projected_relationship_names = {
|
|
125
|
+
path.parts[0]
|
|
126
|
+
for path in ast.projection.paths
|
|
127
|
+
if path.model is source
|
|
128
|
+
and len(path.parts) == 1
|
|
129
|
+
and path.parts[0] in (meta.relationships if meta else {})
|
|
130
|
+
}
|
|
131
|
+
select_items = [
|
|
132
|
+
f"{self._path(path)} AS {self.dialect.quote(path.parts[-1])}"
|
|
133
|
+
for path in ast.projection.paths
|
|
134
|
+
if not (
|
|
135
|
+
path.model is source
|
|
136
|
+
and path.parts
|
|
137
|
+
and path.parts[0] in projected_relationship_names
|
|
138
|
+
)
|
|
139
|
+
]
|
|
140
|
+
if joined and meta is not None:
|
|
141
|
+
root_pk = meta.fields.get(meta.primary_key_field)
|
|
142
|
+
root_pk_column = root_pk.column_name if root_pk else meta.primary_key_field
|
|
143
|
+
select_items.append(
|
|
144
|
+
f"{self.dialect.quote('r0')}.{self.dialect.quote(root_pk_column)} "
|
|
145
|
+
f"AS {self.dialect.quote('__renus_root_pk')}"
|
|
146
|
+
)
|
|
147
|
+
for spec in joined:
|
|
148
|
+
if spec["path"][0] not in projected_relationship_names:
|
|
149
|
+
continue
|
|
150
|
+
target_meta = spec["meta"]
|
|
151
|
+
target_ref = self.dialect.quote(spec["alias"])
|
|
152
|
+
prefix = spec["prefix"]
|
|
153
|
+
for field_name in target_meta.fields:
|
|
154
|
+
column = self._field_name(target_meta.model, field_name)
|
|
155
|
+
alias = self.dialect.quote(
|
|
156
|
+
f"__renus_joined__{prefix}__{field_name}"
|
|
157
|
+
)
|
|
158
|
+
select_items.append(
|
|
159
|
+
f"{target_ref}.{self.dialect.quote(column)} AS {alias}"
|
|
160
|
+
)
|
|
161
|
+
select_clause = ", ".join(select_items) if select_items else "1"
|
|
118
162
|
else:
|
|
119
163
|
if joined:
|
|
120
164
|
select_parts = [f'{self.dialect.quote("r0")}.*']
|
|
@@ -220,25 +264,48 @@ class SQLCompiler:
|
|
|
220
264
|
joined=tuple(joined),
|
|
221
265
|
root_limit=ast.limit if joined else None,
|
|
222
266
|
root_offset=ast.offset if joined else None,
|
|
267
|
+
projection_paths=(ast.projection.paths if ast.projection else ()),
|
|
223
268
|
)
|
|
224
269
|
|
|
225
270
|
def _joined_relationships(self, ast: QueryAST) -> list[dict[str, Any]]:
|
|
226
271
|
"""Build adapter row metadata and SQL joins for eager relationships."""
|
|
227
|
-
if ast.
|
|
272
|
+
if ast.aggregates:
|
|
228
273
|
return []
|
|
229
274
|
meta = getattr(ast.source, "__db_metadata__", None)
|
|
230
275
|
if meta is None:
|
|
231
276
|
return []
|
|
232
277
|
|
|
278
|
+
projected_relationships = tuple(
|
|
279
|
+
dict.fromkeys(
|
|
280
|
+
path.parts[0]
|
|
281
|
+
for path in (ast.projection.paths if ast.projection else ())
|
|
282
|
+
if path.model is ast.source
|
|
283
|
+
and len(path.parts) == 1
|
|
284
|
+
and path.parts[0] in meta.relationships
|
|
285
|
+
)
|
|
286
|
+
)
|
|
287
|
+
projected_relationship_names = set(projected_relationships)
|
|
288
|
+
if ast.projection and not projected_relationships:
|
|
289
|
+
return []
|
|
290
|
+
|
|
233
291
|
result: list[dict[str, Any]] = []
|
|
234
292
|
alias_number = 0
|
|
235
293
|
requested: dict[tuple[str, ...], Include] = {
|
|
236
|
-
include.path.parts: include
|
|
294
|
+
include.path.parts: include
|
|
295
|
+
for include in ast.includes
|
|
296
|
+
if not ast.projection
|
|
297
|
+
or (
|
|
298
|
+
include.path.parts
|
|
299
|
+
and include.path.parts[0] in projected_relationship_names
|
|
300
|
+
)
|
|
237
301
|
}
|
|
238
|
-
for name
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
302
|
+
for name in projected_relationships:
|
|
303
|
+
requested.setdefault((name,), Include(Path(ast.source, (name,))))
|
|
304
|
+
if not ast.projection:
|
|
305
|
+
for name, rel in meta.relationships.items():
|
|
306
|
+
loading = getattr(rel.loading, "value", rel.loading)
|
|
307
|
+
if loading == "joined":
|
|
308
|
+
requested.setdefault((name,), Include(Path(ast.source, (name,))))
|
|
242
309
|
|
|
243
310
|
def add(
|
|
244
311
|
model: type,
|