Skip to content

Commit

Permalink
back to version 310
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTraveylan committed Aug 29, 2024
1 parent 7c21ca9 commit efecf5d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/database/repository.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from typing import Generic, List, Optional, TypeVar

from sqlalchemy.exc import NoResultFound
from sqlmodel import Session, select

from app.exceptions import DatabaseException, NotFoundException

T = TypeVar("T")


class Repository[T]:
__model__: type[T]
class Repository(Generic[T]):
__model__: type

@staticmethod
def create(session: Session, item: T) -> T:
Expand Down Expand Up @@ -47,7 +51,7 @@ def get_or_raise(self, session: Session, **kwargs) -> T:

return first_item

def get_or_none(self, session: Session, **kwargs) -> T | None:
def get_or_none(self, session: Session, **kwargs) -> Optional[T]:
filter_kwargs = [
getattr(self.__model__, key) == value for key, value in kwargs.items()
]
Expand All @@ -57,7 +61,7 @@ def get_or_none(self, session: Session, **kwargs) -> T | None:

return item

def get_all(self, session: Session) -> list[T]:
def get_all(self, session: Session) -> List[T]:
return session.exec(select(self.__model__)).all()

def delete(self, session: Session, id_: int) -> bool:
Expand Down

0 comments on commit efecf5d

Please sign in to comment.