Skip to content

Commit

Permalink
Merge pull request #44 from seamusic-official/rm/extra_fields
Browse files Browse the repository at this point in the history
fix makefile + configs
  • Loading branch information
dmkjfs authored Dec 8, 2024
2 parents 39dd94c + 208c8f3 commit 5587dbe
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ run-local:
poetry run uvicorn src.api.app:app --host 0.0.0.0 --port 8000 --reload --reload-dir . --log-config=log_config.ini --log-level=debug

build:
poetry run sudo docker compose -f docker-compose.$(for).yml build
poetry run docker-compose -f docker-compose.$(for).yml build

start:
poetry run sudo docker compose -f docker-compose.$(for).yml up --force-recreate --remove-orphans
poetry run docker-compose -f docker-compose.$(for).yml up --force-recreate --remove-orphans

up:
poetry run sudo docker compose -f docker-compose.$(for).yml up --force-recreate --remove-orphans -d
poetry run docker-compose -f docker-compose.$(for).yml up --force-recreate --remove-orphans -d

stop:
poetry run docker-compose -f docker-compose.$(for).yml stop
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,4 @@ strict_optional = true
ignore_missing_imports = true

[tool.pytest.ini_options]
pythonpath = [ ".", "src",]
asyncio_mode="auto"
env_files = [".env.test"]
asyncio_mode = "auto"
25 changes: 15 additions & 10 deletions src/repositories/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
from src.core.config import settings
from src.models.base import Base

engine = create_async_engine(
url=settings.db_url,
echo=settings.echo,
)
sessionmaker = async_sessionmaker(
bind=engine,
expire_on_commit=False,
)


@dataclass
class BaseDatabaseRepository(ABC):
Expand All @@ -22,34 +31,30 @@ class DatabaseRepositories(ABC):
@dataclass
class SQLAlchemyRepository(BaseDatabaseRepository):

engine = create_async_engine(url=settings.db_url, echo=settings.echo, pool_pre_ping=True)
sessionmaker = async_sessionmaker(engine, expire_on_commit=False)

async def add(self, obj: Base) -> None:
async with self.sessionmaker() as session:
async with sessionmaker() as session:
session.add(obj)
await session.commit()
await self.engine.dispose()

async def merge(self, obj: Base) -> None:
async with self.sessionmaker() as session:
async with sessionmaker() as session:
await session.merge(obj)

async def execute(self, statement: Executable) -> None:
async with self.sessionmaker() as session:
async with sessionmaker() as session:
await session.execute(statement)

async def get(self, table: type[Base], primary_key: Any): # type: ignore[no-untyped-def]
async with self.sessionmaker() as session:
async with sessionmaker() as session:
model = await session.get(table, primary_key)
return model

async def scalar(self, statement: Executable) -> Any:
async with self.sessionmaker() as session:
async with sessionmaker() as session:
item = await session.scalar(statement)
return item

async def scalars(self, statement: Executable) -> Iterable:
async with self.sessionmaker() as session:
async with sessionmaker() as session:
items = await session.scalars(statement)
return items
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from fastapi.testclient import TestClient

from src.api.app import app


Expand Down
3 changes: 2 additions & 1 deletion tests/connections/database/test_postgres.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from src.core.config import settings
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker

from src.core.config import settings

test_engine = create_async_engine(settings.db_url, echo=True)

sessionmaker_test = async_sessionmaker(test_engine)
Expand Down

0 comments on commit 5587dbe

Please sign in to comment.