Skip to content

Commit

Permalink
Merge pull request grillazz#115 from grillazz/sqlalchemy-2
Browse files Browse the repository at this point in the history
use DeclarativeBase class for models Base
  • Loading branch information
grillazz authored Sep 18, 2023
2 parents 8134ac4 + 3294839 commit e086a4d
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@
from fastapi import HTTPException, status
from sqlalchemy.exc import SQLAlchemyError, IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import as_declarative, declared_attr
from sqlalchemy.orm import declared_attr, DeclarativeBase


@as_declarative()
class BaseReadOnly:
id: Any
__name__: str
# Generate __tablename__ automatically

@declared_attr
def __tablename__(self) -> str:
return self.__name__.lower()


@as_declarative()
class Base:
class Base(DeclarativeBase):
id: Any
__name__: str
# Generate __tablename__ automatically
Expand Down

0 comments on commit e086a4d

Please sign in to comment.