fastapi-tortoise-orm批量插入數據庫


  • 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}")
       
    •   

       

       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM