主键 ID
此方法使用主键 pk
参数,详见:主键
示例¶
select_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 select(self, db: AsyncSession, pk: int) -> ModelIns:
return await self.select_model(db, pk)