主键 ID
async def delete_model(
self,
session: AsyncSession,
pk: int,
flush: bool = False,
commit: bool = False,
) -> int:
示例¶
delete_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 CRUDIns(CRUDPlus[ModelIns]):
async def delete(self, db: AsyncSession, pk: int) -> int:
return await self.delete_model(db, pk)