High
Fastapi
Use async database operations
Official
Rule Description
Use async database drivers with FastAPI:
- asyncpg for PostgreSQL
- SQLAlchemy 2.0 async mode
- databases package for simple queries
```python
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
engine = create_async_engine(
"postgresql+asyncpg://user:pass@localhost/db",
echo=True,
)
async def get_user(db: AsyncSession, user_id: int) -> User | None:
result = await db.execute(
select(User).where(User.id == user_id)
)
return result.scalar_one_or_none()
```
Included in Rulesets
Django Best Practices
36 rules • 1 standard
FastAPI Guidelines
36 rules • 1 standard
Python Standards
33 rules • 2 standards
PostgreSQL Standards
25 rules • 0 standards
MySQL Standards
25 rules • 0 standards
MongoDB Best Practices
25 rules • 1 standard
Redis Guidelines
25 rules • 0 standards
SQLite Standards
25 rules • 0 standards
Code Review Standards
58 rules • 0 standards
Add This Rule
Sign in to add this rule to your workspace
Sign in with GitHubDetails
- Severity
- High
- Category
- Fastapi
- Used in
- 9 rulesets