- tortoise-orm官方
- 異步 類方法 bulk_create(對象, batch_size = None, using_db = None)
- 批量插入操作將盡量保證在 DB 中創建的對象具有所有默認值和生成的字段集,但在 Python 中可能是不完整的引用
-
@cases.post("/test/", name="批量新增") async def create(case: List[models.CaseIn_Pydantic]): result = [models.Case(**c.dict(exclude_unset=True)) for c in case] try: await models.Case.bulk_create(result) # bulk_create批量插入操作 return core.Success(data=await models.Case.from_queryset(models.Case)) except Exception as e: return core.Fail(message=f"創建失敗.{e}")
-