From 17258378c398b10e843408f24647485a6d15dbd5 Mon Sep 17 00:00:00 2001 From: inter Date: Mon, 8 Sep 2025 16:35:53 +0800 Subject: [PATCH] Add File --- backend/common/core/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 backend/common/core/models.py 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