更好更规范的类型注解;AGENTSMD试作

This commit is contained in:
UnCLAS-Prommer
2026-02-13 16:24:03 +08:00
parent b80b5afe2a
commit c14736ffca
5 changed files with 91 additions and 73 deletions

View File

@@ -1,6 +1,28 @@
from abc import ABC, abstractmethod
from typing import Self, TypeVar, Generic, TYPE_CHECKING
import copy
if TYPE_CHECKING:
from sqlmodel import SQLModel
T = TypeVar("T", bound="SQLModel")
class BaseDataModel:
def deepcopy(self):
return copy.deepcopy(self)
class BaseDatabaseDataModel(ABC, Generic[T]):
@abstractmethod
@classmethod
def from_db_instance(cls, db_record: T) -> Self:
"""从数据库实例创建数据模型对象"""
raise NotImplementedError
@abstractmethod
def to_db_instance(self) -> T:
"""将数据模型对象转换为数据库实例"""
raise NotImplementedError