feat: db model mixins
This commit is contained in:
parent
0baa50d10f
commit
7e1ab6c6ee
1 changed files with 23 additions and 2 deletions
|
|
@ -5,8 +5,8 @@ Global database models
|
|||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import DateTime, JSON
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from sqlalchemy import DateTime, JSON, func
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
|
||||
class CustomBase(DeclarativeBase):
|
||||
|
|
@ -14,3 +14,24 @@ class CustomBase(DeclarativeBase):
|
|||
datetime: DateTime(timezone=True),
|
||||
dict[str, Any]: JSON,
|
||||
}
|
||||
|
||||
|
||||
class ActivatedMixin:
|
||||
active: Mapped[bool] = mapped_column(default=True)
|
||||
|
||||
|
||||
class DeletedTimestampMixin:
|
||||
deleted_at: Mapped[datetime | None] = mapped_column(nullable=True)
|
||||
|
||||
|
||||
class DescriptionMixin:
|
||||
description: Mapped[str]
|
||||
|
||||
|
||||
class IdMixin:
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
|
||||
|
||||
class TimestampMixin:
|
||||
created_at: Mapped[datetime] = mapped_column(default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(default=func.now(), onupdate=func.now())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue