Fetch a single record by its primary key ID.
(self, id: Any)
| 37 | _session_ctx.reset(token) |
| 38 | |
| 39 | async def get(self, id: Any) -> ModelType | None: |
| 40 | """Fetch a single record by its primary key ID.""" |
| 41 | async with self.session() as db: |
| 42 | if hasattr(db, "get"): |
| 43 | return await db.get(self.model, id) |
| 44 | # Fallback for custom mock DB clients in tests |
| 45 | stmt = select(self.model).where(self.model.id == id) |
| 46 | result = await db.execute(stmt) |
| 47 | return result.scalar_one_or_none() |
| 48 | |
| 49 | async def is_empty(self) -> bool: |
| 50 | """Check if the table is empty (no records).""" |