26 lines
574 B
Python
26 lines
574 B
Python
|
|
import uuid
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from sqlalchemy import DateTime, func
|
||
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||
|
|
|
||
|
|
|
||
|
|
class Base(DeclarativeBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class TimestampMixin:
|
||
|
|
created_at: Mapped[datetime] = mapped_column(
|
||
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||
|
|
)
|
||
|
|
updated_at: Mapped[datetime] = mapped_column(
|
||
|
|
DateTime(timezone=True),
|
||
|
|
server_default=func.now(),
|
||
|
|
onupdate=func.now(),
|
||
|
|
nullable=False,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def new_uuid() -> uuid.UUID:
|
||
|
|
return uuid.uuid4()
|