wheke-sqlmodel 0.3.0__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,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,3 @@
1
+ # Wheke SQLModel
2
+
3
+ Add sql capabilities to wheke with SQLModel
@@ -0,0 +1,129 @@
1
+ [project]
2
+ name = "wheke-sqlmodel"
3
+ version = "0.3.0"
4
+ description = "Add sql capabilities to wheke with SQLModel"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "aiosqlite",
9
+ "anyio",
10
+ "sqlmodel",
11
+ "wheke",
12
+ ]
13
+
14
+ [dependency-groups]
15
+ dev = [
16
+ "httpx",
17
+ "isort",
18
+ "mypy",
19
+ "pytest",
20
+ "pytest-cov",
21
+ "ruff",
22
+ ]
23
+
24
+ [tool.pytest.ini_options]
25
+ pythonpath = [
26
+ "src"
27
+ ]
28
+
29
+ [tool.coverage.run]
30
+ relative_files = true
31
+ branch = true
32
+ parallel = true
33
+ omit = []
34
+
35
+ [tool.coverage.report]
36
+ exclude_lines = [
37
+ "no cov",
38
+ "if __name__ == .__main__.:",
39
+ "if TYPE_CHECKING:",
40
+ ]
41
+
42
+ [tool.isort]
43
+ profile = "black"
44
+ skip = [
45
+ ".env",
46
+ ".hatch",
47
+ ".mypy_cache",
48
+ ".venv",
49
+ "__pycache__",
50
+ "env",
51
+ "venv",
52
+ ]
53
+
54
+ [tool.mypy]
55
+ disallow_incomplete_defs = true
56
+ check_untyped_defs = true
57
+ warn_unused_ignores = true
58
+ exclude = """
59
+ .env
60
+ | .hatch
61
+ | .mypy_cache
62
+ | .venv
63
+ | __pycache__
64
+ | env
65
+ | venv
66
+ """
67
+
68
+ [tool.ruff]
69
+ exclude = [
70
+ ".env",
71
+ ".hatch",
72
+ ".mypy_cache",
73
+ ".venv",
74
+ "__pycache__",
75
+ "env",
76
+ "venv",
77
+ ]
78
+
79
+ [tool.ruff.lint]
80
+ select = [
81
+ "A",
82
+ "ARG",
83
+ "B",
84
+ "C",
85
+ "DTZ",
86
+ "E",
87
+ "EM",
88
+ "F",
89
+ "FBT",
90
+ "I",
91
+ "ICN",
92
+ "ISC",
93
+ "N",
94
+ "PLC",
95
+ "PLE",
96
+ "PLR",
97
+ "PLW",
98
+ "Q",
99
+ "RUF",
100
+ "S",
101
+ "T",
102
+ "TID",
103
+ "UP",
104
+ "W",
105
+ "YTT",
106
+ ]
107
+ ignore = [
108
+ # Same line string implicit string concatenation
109
+ "ISC001",
110
+ # Allow non-abstract empty methods in abstract base classes
111
+ "B027",
112
+ # Ignore checks for possible passwords
113
+ "S105", "S106", "S107",
114
+ # Ignore complexity
115
+ "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
116
+ # Relative imports
117
+ "TID252",
118
+ ]
119
+ unfixable = [
120
+ # Don't touch unused imports
121
+ "F401",
122
+ ]
123
+
124
+ [tool.ruff.lint.isort]
125
+ known-first-party = ["wheke_sqlmodel"]
126
+
127
+ [tool.ruff.lint.per-file-ignores]
128
+ # Tests can use magic values, assertions, and relative imports
129
+ "tests/**/*" = ["PLR2004", "S101", "TID252"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -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
+ ]
@@ -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)
@@ -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
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,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/wheke_sqlmodel/__init__.py
4
+ src/wheke_sqlmodel/_cli.py
5
+ src/wheke_sqlmodel/_pod.py
6
+ src/wheke_sqlmodel/_service.py
7
+ src/wheke_sqlmodel/_settings.py
8
+ src/wheke_sqlmodel/py.typed
9
+ src/wheke_sqlmodel.egg-info/PKG-INFO
10
+ src/wheke_sqlmodel.egg-info/SOURCES.txt
11
+ src/wheke_sqlmodel.egg-info/dependency_links.txt
12
+ src/wheke_sqlmodel.egg-info/requires.txt
13
+ src/wheke_sqlmodel.egg-info/top_level.txt
14
+ tests/test_app.py
@@ -0,0 +1,4 @@
1
+ aiosqlite
2
+ anyio
3
+ sqlmodel
4
+ wheke
@@ -0,0 +1 @@
1
+ wheke_sqlmodel
@@ -0,0 +1,12 @@
1
+ from fastapi import status
2
+ from fastapi.testclient import TestClient
3
+
4
+
5
+ def test_list_entries(client: TestClient) -> None:
6
+ response = client.post("/entries", json={"value": "test"})
7
+ assert response.status_code == status.HTTP_201_CREATED
8
+
9
+ response = client.get("/entries")
10
+ assert response.status_code == status.HTTP_200_OK
11
+
12
+ assert len(response.json()) == 1