主键 ID
async def update_model(
self,
session: AsyncSession,
pk: int,
obj: UpdateSchema | dict[str, Any],
flush: bool = False,
commit: bool = False,
**kwargs,
) -> int:
示例¶
update_model
from pydantic import BaseModel
from sqlalchemy_crud_plus import CRUDPlus
from sqlalchemy import Mapped, mapped_column
from sqlalchemy import DeclarativeBase as Base
from sqlalchemy.ext.asyncio import AsyncSession
class ModelIns(Base):
# your sqlalchemy model
# define your primary_key
custom_id: Mapped[int] = mapped_column(primary_key=True, index=True, autoincrement=True)
class UpdateIns(BaseModel):
# your pydantic schema
pass
class CRUDIns(CRUDPlus[ModelIns]):
async def create(self, db: AsyncSession, pk: int, obj: UpdateIns) -> int:
return await self.update_model(db, pk, obj)