austial-orm 0.1.5__py3-none-any.whl

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.
@@ -0,0 +1,3 @@
1
+ from austial.orm.database_module import DATABASE_ENGINE, DATABASE_SESSION_FACTORY, DatabaseModule
2
+
3
+ __all__ = ["DATABASE_ENGINE", "DATABASE_SESSION_FACTORY", "DatabaseModule"]
@@ -0,0 +1,61 @@
1
+ """``DatabaseModule`` -- mirrors ``@nestjs/typeorm``'s ``TypeOrmModule.forRoot[Async]()``.
2
+
3
+ Backed by SQLAlchemy's async engine; defaults to a local sqlite file so a
4
+ freshly generated project works with zero external services.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from collections.abc import Callable, Sequence
10
+ from typing import Any
11
+
12
+ from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
13
+
14
+ from austial.common.decorators.modules import Module
15
+ from austial.core.dynamic_module import DynamicModule
16
+
17
+ DATABASE_ENGINE = "DATABASE_ENGINE"
18
+ DATABASE_SESSION_FACTORY = "DATABASE_SESSION_FACTORY"
19
+
20
+
21
+ @Module()
22
+ class DatabaseModule:
23
+ """Import via ``DatabaseModule.for_root(url=...)`` or
24
+ ``DatabaseModule.for_root_async(use_factory=..., inject=[ConfigService])``,
25
+ mirroring Nest's TypeORM dynamic-module conventions. Exposes two tokens
26
+ other providers can ``Inject(...)``: ``DATABASE_ENGINE`` and
27
+ ``DATABASE_SESSION_FACTORY``."""
28
+
29
+ @staticmethod
30
+ def for_root(url: str = "sqlite+aiosqlite:///./austial.db", **engine_kwargs: Any) -> DynamicModule:
31
+ engine = create_async_engine(url, **engine_kwargs)
32
+ session_factory = async_sessionmaker(engine, expire_on_commit=False)
33
+ return DynamicModule(
34
+ module=DatabaseModule,
35
+ providers=[
36
+ {"provide": DATABASE_ENGINE, "useValue": engine},
37
+ {"provide": DATABASE_SESSION_FACTORY, "useValue": session_factory},
38
+ ],
39
+ exports=[DATABASE_ENGINE, DATABASE_SESSION_FACTORY],
40
+ )
41
+
42
+ @staticmethod
43
+ def for_root_async(*, use_factory: Callable[..., str], inject: Sequence[Any] = ()) -> DynamicModule:
44
+ def _build_engine(*deps: Any):
45
+ return create_async_engine(use_factory(*deps))
46
+
47
+ def _build_session_factory(engine: Any):
48
+ return async_sessionmaker(engine, expire_on_commit=False)
49
+
50
+ return DynamicModule(
51
+ module=DatabaseModule,
52
+ providers=[
53
+ {"provide": DATABASE_ENGINE, "useFactory": _build_engine, "inject": list(inject)},
54
+ {
55
+ "provide": DATABASE_SESSION_FACTORY,
56
+ "useFactory": _build_session_factory,
57
+ "inject": [DATABASE_ENGINE],
58
+ },
59
+ ],
60
+ exports=[DATABASE_ENGINE, DATABASE_SESSION_FACTORY],
61
+ )
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: austial-orm
3
+ Version: 0.1.5
4
+ Summary: DatabaseModule wrapping SQLAlchemy's async engine/session -- mirrors @nestjs/typeorm (no main-monorepo equivalent).
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: aiosqlite>=0.20.0
7
+ Requires-Dist: austial-common
8
+ Requires-Dist: austial-core
9
+ Requires-Dist: sqlalchemy>=2.0.30
@@ -0,0 +1,5 @@
1
+ austial/orm/__init__.py,sha256=2K_ltYgBDoyRm7RyrN91Kwxt-Zn69fdTPqUUz_-R8kA,175
2
+ austial/orm/database_module.py,sha256=XWMGBNIi2GjiCCR7dZn07x9AF7UCkp8VS9ZZhyHcSbY,2373
3
+ austial_orm-0.1.5.dist-info/METADATA,sha256=XNqS2AhxGP7T1IlcqDDr95zIChaW9hBIMhsVZoMd-bA,329
4
+ austial_orm-0.1.5.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
5
+ austial_orm-0.1.5.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any