feat(mixin): add TableBaseMixin and UUIDTableBaseMixin for async CRUD operations
- Implemented TableBaseMixin providing generic CRUD methods and automatic timestamp management. - Introduced UUIDTableBaseMixin for models using UUID as primary keys. - Added ListResponse for standardized paginated responses. - Created TimeFilterRequest and PaginationRequest for filtering and pagination parameters. - Enhanced get_with_count method to return both item list and total count. - Included validation for time filter parameters in TimeFilterRequest. - Improved documentation and usage examples throughout the code.
This commit is contained in:
@@ -1,24 +1,41 @@
|
||||
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from enum import StrEnum
|
||||
from typing import TYPE_CHECKING
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
|
||||
from sqlmodel import Field, Relationship, UniqueConstraint, Column, func, DateTime
|
||||
|
||||
from .base import TableBase
|
||||
from .base import SQLModelBase
|
||||
from .mixin import TableBaseMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .user import User
|
||||
|
||||
class Tag(TableBase, table=True):
|
||||
|
||||
class TagType(StrEnum):
|
||||
"""标签类型枚举"""
|
||||
MANUAL = "manual"
|
||||
"""手动标签"""
|
||||
AUTOMATIC = "automatic"
|
||||
"""自动标签"""
|
||||
|
||||
|
||||
class Tag(SQLModelBase, TableBaseMixin):
|
||||
"""标签模型"""
|
||||
|
||||
__table_args__ = (UniqueConstraint("name", "user_id", name="uq_tag_name_user"),)
|
||||
|
||||
name: str = Field(max_length=255, description="标签名称")
|
||||
icon: str | None = Field(default=None, max_length=255, description="标签图标")
|
||||
color: str | None = Field(default=None, max_length=255, description="标签颜色")
|
||||
type: int = Field(default=0, sa_column_kwargs={"server_default": "0"}, description="标签类型: 0=手动, 1=自动")
|
||||
name: str = Field(max_length=255)
|
||||
"""标签名称"""
|
||||
|
||||
icon: str | None = Field(default=None, max_length=255)
|
||||
"""标签图标"""
|
||||
|
||||
color: str | None = Field(default=None, max_length=255)
|
||||
"""标签颜色"""
|
||||
|
||||
type: TagType = Field(default=TagType.MANUAL, sa_column_kwargs={"server_default": "'manual'"})
|
||||
"""标签类型"""
|
||||
expression: str | None = Field(default=None, description="自动标签的匹配表达式")
|
||||
|
||||
# 外键
|
||||
|
||||
Reference in New Issue
Block a user