taolib.testing._base.repository#
泛型 Repository 基类模块。
提供异步 MongoDB Repository 的通用 CRUD 操作实现。
Attributes#
Classes#
异步 Repository 基类。 |
Module Contents#
- taolib.testing._base.repository.T#
- class taolib.testing._base.repository.AsyncRepository(collection: motor.motor_asyncio.AsyncIOMotorCollection, model_class: type[T])#
-
异步 Repository 基类。
- _collection#
- _model_class#
- async get_by_id(doc_id: str) T | None#
根据 ID 获取文档。
- 参数:
doc_id -- 文档 ID
- 返回:
Pydantic 模型实例,如果不存在则返回 None
- async update(doc_id: str, updates: dict[str, Any]) T | None#
更新文档。
- 参数:
doc_id -- 文档 ID
updates -- 更新字段字典
- 返回:
更新后的 Pydantic 模型实例,如果不存在则返回 None