wheke-sqlmodel 0.3.0__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.
- wheke_sqlmodel/__init__.py +11 -0
- wheke_sqlmodel/_cli.py +30 -0
- wheke_sqlmodel/_pod.py +17 -0
- wheke_sqlmodel/_service.py +50 -0
- wheke_sqlmodel/_settings.py +13 -0
- wheke_sqlmodel/py.typed +0 -0
- wheke_sqlmodel-0.3.0.dist-info/METADATA +14 -0
- wheke_sqlmodel-0.3.0.dist-info/RECORD +10 -0
- wheke_sqlmodel-0.3.0.dist-info/WHEEL +5 -0
- wheke_sqlmodel-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from ._pod import sqlmodel_pod
|
|
2
|
+
from ._service import SQLModelService, get_sqlmodel_service
|
|
3
|
+
from ._settings import SQLITE_DRIVER, SQLModelSettings
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"SQLITE_DRIVER",
|
|
7
|
+
"SQLModelService",
|
|
8
|
+
"SQLModelSettings",
|
|
9
|
+
"get_sqlmodel_service",
|
|
10
|
+
"sqlmodel_pod",
|
|
11
|
+
]
|
wheke_sqlmodel/_cli.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import anyio
|
|
2
|
+
import typer
|
|
3
|
+
from rich.console import Console
|
|
4
|
+
from typer import Context
|
|
5
|
+
from wheke import get_container
|
|
6
|
+
|
|
7
|
+
from ._service import get_sqlmodel_service
|
|
8
|
+
|
|
9
|
+
cli = typer.Typer(short_help="SQLModel commands")
|
|
10
|
+
console = Console()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@cli.command()
|
|
14
|
+
def create_db(ctx: Context) -> None:
|
|
15
|
+
container = get_container(ctx)
|
|
16
|
+
service = get_sqlmodel_service(container)
|
|
17
|
+
|
|
18
|
+
console.print("Creating database...")
|
|
19
|
+
|
|
20
|
+
anyio.run(service.create_db)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@cli.command()
|
|
24
|
+
def drop_db(ctx: Context) -> None:
|
|
25
|
+
container = get_container(ctx)
|
|
26
|
+
service = get_sqlmodel_service(container)
|
|
27
|
+
|
|
28
|
+
console.print("Droping database...")
|
|
29
|
+
|
|
30
|
+
anyio.run(service.drop_db)
|
wheke_sqlmodel/_pod.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from wheke import Pod, ServiceConfig
|
|
2
|
+
|
|
3
|
+
from ._cli import cli
|
|
4
|
+
from ._service import SQLModelService, sqlmodel_service_factory
|
|
5
|
+
|
|
6
|
+
sqlmodel_pod = Pod(
|
|
7
|
+
"sqlmodel",
|
|
8
|
+
services=[
|
|
9
|
+
ServiceConfig(
|
|
10
|
+
SQLModelService,
|
|
11
|
+
sqlmodel_service_factory,
|
|
12
|
+
is_singleton=True,
|
|
13
|
+
singleton_cleanup_method="dispose",
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
cli=cli,
|
|
17
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from collections.abc import AsyncGenerator
|
|
2
|
+
from contextlib import asynccontextmanager
|
|
3
|
+
|
|
4
|
+
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
|
5
|
+
from sqlmodel import SQLModel
|
|
6
|
+
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
7
|
+
from svcs import Container
|
|
8
|
+
from wheke import WhekeSettings, get_service, get_settings
|
|
9
|
+
|
|
10
|
+
from ._settings import SQLModelSettings
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SQLModelService:
|
|
14
|
+
engine: AsyncEngine
|
|
15
|
+
|
|
16
|
+
def __init__(self, *, settings: SQLModelSettings) -> None:
|
|
17
|
+
self.engine = create_async_engine(
|
|
18
|
+
settings.connection_string,
|
|
19
|
+
connect_args={
|
|
20
|
+
"check_same_thread": False,
|
|
21
|
+
},
|
|
22
|
+
echo=settings.echo_operations,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
@asynccontextmanager
|
|
27
|
+
async def session(self) -> AsyncGenerator[AsyncSession]:
|
|
28
|
+
async with AsyncSession(self.engine) as _session:
|
|
29
|
+
yield _session
|
|
30
|
+
|
|
31
|
+
async def create_db(self) -> None:
|
|
32
|
+
async with self.engine.begin() as conn:
|
|
33
|
+
await conn.run_sync(SQLModel.metadata.create_all)
|
|
34
|
+
|
|
35
|
+
async def drop_db(self) -> None:
|
|
36
|
+
async with self.engine.begin() as conn:
|
|
37
|
+
await conn.run_sync(SQLModel.metadata.drop_all)
|
|
38
|
+
|
|
39
|
+
async def dispose(self) -> None:
|
|
40
|
+
await self.engine.dispose()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def sqlmodel_service_factory(container: Container) -> SQLModelService:
|
|
44
|
+
settings = get_settings(container, WhekeSettings).get_feature(SQLModelSettings)
|
|
45
|
+
|
|
46
|
+
return SQLModelService(settings=settings)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_sqlmodel_service(container: Container) -> SQLModelService:
|
|
50
|
+
return get_service(container, SQLModelService)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import ClassVar
|
|
2
|
+
|
|
3
|
+
from wheke import FeatureSettings
|
|
4
|
+
|
|
5
|
+
SQLITE_DRIVER = "sqlite+aiosqlite"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SQLModelSettings(FeatureSettings):
|
|
9
|
+
__feature_name__: ClassVar[str] = "sqlmodel"
|
|
10
|
+
|
|
11
|
+
connection_string: str = f"{SQLITE_DRIVER}:///database.db"
|
|
12
|
+
|
|
13
|
+
echo_operations: bool = False
|
wheke_sqlmodel/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wheke-sqlmodel
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Add sql capabilities to wheke with SQLModel
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: aiosqlite
|
|
8
|
+
Requires-Dist: anyio
|
|
9
|
+
Requires-Dist: sqlmodel
|
|
10
|
+
Requires-Dist: wheke
|
|
11
|
+
|
|
12
|
+
# Wheke SQLModel
|
|
13
|
+
|
|
14
|
+
Add sql capabilities to wheke with SQLModel
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
wheke_sqlmodel/__init__.py,sha256=gm5QT4sfPbaleU3XoeHHEnIdrKJj7jiZy_FNxmBPRyg,277
|
|
2
|
+
wheke_sqlmodel/_cli.py,sha256=kEdsK-bzrY59B0XhmIvVSbWRCaFosYlVb9DstJjPa_c,651
|
|
3
|
+
wheke_sqlmodel/_pod.py,sha256=41x9ReGxjH3DFt4jSYpwORpTaF-qWl_P2-bpW0klEk0,378
|
|
4
|
+
wheke_sqlmodel/_service.py,sha256=Mmp2sd9-7cm8HbGD1FjD62P39mwkgrrE_dk_gIWNI4g,1581
|
|
5
|
+
wheke_sqlmodel/_settings.py,sha256=7ibjtz8X3O8otRGuyIj62lswrcVROztnyHxzDhjKvI0,290
|
|
6
|
+
wheke_sqlmodel/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
wheke_sqlmodel-0.3.0.dist-info/METADATA,sha256=-X_C9MDbFE7D0OF5jGLNZrcZA-Kc04usT5t6CtGhZ0I,329
|
|
8
|
+
wheke_sqlmodel-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
9
|
+
wheke_sqlmodel-0.3.0.dist-info/top_level.txt,sha256=xn3IbC1JQzfXO8TkB3mB5AdkRJ53uNhOCawQmj_Kh9E,15
|
|
10
|
+
wheke_sqlmodel-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wheke_sqlmodel
|