austial-orm 0.1.5__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.
|
@@ -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,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "austial-orm"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "DatabaseModule wrapping SQLAlchemy's async engine/session -- mirrors @nestjs/typeorm (no main-monorepo equivalent)."
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"austial-common",
|
|
8
|
+
"austial-core",
|
|
9
|
+
"sqlalchemy>=2.0.30",
|
|
10
|
+
"aiosqlite>=0.20.0",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
15
|
+
build-backend = "hatchling.build"
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/austial"]
|
|
19
|
+
|
|
20
|
+
[tool.uv.sources]
|
|
21
|
+
austial-common = { workspace = true }
|
|
22
|
+
austial-core = { workspace = true }
|
|
23
|
+
|
|
24
|
+
[tool.hatch.version]
|
|
25
|
+
source = "vcs"
|
|
26
|
+
|
|
27
|
+
[tool.hatch.version.raw-options]
|
|
28
|
+
root = "../.."
|
|
@@ -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
|
+
)
|