Skip to content

Commit f4c3b6c

Browse files
committed
add dinamic settings data base
1 parent 368164a commit f4c3b6c

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

api_v1/tests/conftest.py

Whitespace-only changes.

config/database/db_helper.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,37 @@
33
async_scoped_session,
44
AsyncSession,
55
)
6+
from sqlalchemy.pool import Pool
67
from asyncio import current_task
78

89
from typing import AsyncGenerator, Any
910

1011
from config import settings
1112

1213

14+
DATA_BASE_URL = settings.db.url
15+
16+
1317
class DataBaseHelper:
1418
"""
1519
Вспомогательный класс для работы с Базой Данных
1620
"""
17-
def __init__(self) -> None:
18-
self.engine = create_async_engine(
19-
url=settings.db.url,
21+
def __init__(self,
22+
db_url: str = DATA_BASE_URL,
23+
poolclass: Pool | None = None,
24+
) -> None:
25+
self._db_url = db_url
26+
setup = dict(
27+
url=self._db_url,
2028
echo=settings.debug,
2129
)
30+
if poolclass:
31+
setup.update(
32+
poolclass=poolclass,
33+
)
34+
self.engine = create_async_engine(
35+
**setup
36+
)
2237
self.session = async_sessionmaker(
2338
bind=self.engine,
2439
autoflush=False,
@@ -43,3 +58,4 @@ async def session_geter(self) -> AsyncGenerator[AsyncSession, Any]:
4358

4459

4560
db_helper = DataBaseHelper()
61+
db_test = DataBaseHelper

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ prometheus-fastapi-instrumentator = "^7.0.0"
2323

2424
[tool.poetry.group.dev.dependencies]
2525
black = "^24.10.0"
26+
pytest-asyncio = "^0.24.0"
27+
asgi-lifespan = "^2.1.0"
2628

2729
[build-system]
2830
requires = ["poetry-core"]

0 commit comments

Comments
 (0)