Add File
This commit is contained in:
19
backend/common/core/models.py
Normal file
19
backend/common/core/models.py
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user