High Fastapi

Use async database operations

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
View
FastAPI Guidelines
36 rules • 1 standard
View
Python Standards
33 rules • 2 standards
View
PostgreSQL Standards
25 rules • 0 standards
View
MySQL Standards
25 rules • 0 standards
View
MongoDB Best Practices
25 rules • 1 standard
View
Redis Guidelines
25 rules • 0 standards
View
SQLite Standards
25 rules • 0 standards
View
Code Review Standards
58 rules • 0 standards
View

Add This Rule

Sign in to add this rule to your workspace

Sign in with GitHub

Details

Severity
High
Category
Fastapi
Used in
9 rulesets