Loaders¶
Loader options describe how relationship paths should be loaded.
ormdantic.loaders.LoaderStrategy
module-attribute
¶
LoaderStrategy = Literal['joined', 'selectin', 'lazy']
ormdantic.loaders.LoaderOption
dataclass
¶
LoaderOption(path, strategy)
ormdantic.loaders.joined
¶
joined(path)
Load a relationship path with the joined strategy.
Source code in ormdantic/loaders.py
def joined(path: str) -> LoaderOption:
"""Load a relationship path with the joined strategy."""
return LoaderOption(path=path, strategy="joined")
ormdantic.loaders.selectin
¶
selectin(path)
Load a relationship path with the select-in strategy.
Source code in ormdantic/loaders.py
def selectin(path: str) -> LoaderOption:
"""Load a relationship path with the select-in strategy."""
return LoaderOption(path=path, strategy="selectin")
ormdantic.loaders.lazy
¶
lazy(path)
Mark a relationship path for explicit lazy loading.
Source code in ormdantic/loaders.py
def lazy(path: str) -> LoaderOption:
"""Mark a relationship path for explicit lazy loading."""
return LoaderOption(path=path, strategy="lazy")
ormdantic.loaders.loader_depth
¶
loader_depth(load)
Return the maximum eager-loading depth from loader options.
Source code in ormdantic/loaders.py
def loader_depth(load: list[LoaderOption] | None) -> int:
"""Return the maximum eager-loading depth from loader options."""
if not load:
return 0
return max(
(option.depth for option in load if option.strategy != "lazy"), default=0
)