diff --git a/backend/common/core/models.py b/backend/common/core/models.py new file mode 100644 index 0000000..d6488f5 --- /dev/null +++ b/backend/common/core/models.py @@ -0,0 +1,19 @@ +from pydantic import field_validator +from sqlmodel import BigInteger, SQLModel, Field +from typing import Optional + +from common.utils.snowflake import snowflake + +class SnowflakeBase(SQLModel): + id: Optional[int] = Field( + default_factory=snowflake.generate_id, + primary_key=True, + sa_type=BigInteger(), + index=True, + nullable=False + ) + + class Config: + json_encoders = { + int: lambda v: str(v) if isinstance(v, int) and v > (2**53 - 1) else v + } \ No newline at end of file