sqlalchemy-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SQLAlchemy Code Review

SQLAlchemy代码审查

Quick Reference

快速参考

Issue TypeReference
Session lifecycle, context managers, async sessionsreferences/sessions.md
relationship(), lazy loading, N+1, joinedloadreferences/relationships.md
select() vs query(), ORM overhead, bulk opsreferences/queries.md
Alembic patterns, reversible migrations, data migrationsreferences/migrations.md
问题类型参考文档
会话生命周期、上下文管理器、异步会话references/sessions.md
relationship()、延迟加载、N+1查询、joinedloadreferences/relationships.md
select() vs query()、ORM开销、批量操作references/queries.md
Alembic模式、可逆迁移、数据迁移references/migrations.md

Review Checklist

审查检查清单

  • Sessions use context managers (
    with
    ,
    async with
    )
  • No session sharing across requests or threads
  • Sessions closed/cleaned up properly
  • relationship()
    uses appropriate
    lazy
    strategy
  • Explicit
    joinedload
    /
    selectinload
    to avoid N+1
  • No lazy loading in loops (N+1 queries)
  • Using SQLAlchemy 2.0
    select()
    syntax, not legacy
    query()
  • Bulk operations use bulk_insert/bulk_update, not ORM loops
  • Async sessions use proper async context managers
  • Migrations are reversible with
    downgrade()
  • Data migrations use
    op.execute()
    not ORM models
  • Migration dependencies properly ordered
  • 会话使用上下文管理器(
    with
    async with
  • 会话未跨请求或线程共享
  • 会话已正确关闭/清理
  • relationship()
    使用合适的
    lazy
    策略
  • 显式使用
    joinedload
    /
    selectinload
    避免N+1查询
  • 循环中未使用延迟加载(避免N+1查询)
  • 使用SQLAlchemy 2.0的
    select()
    语法,而非旧版
    query()
  • 批量操作使用bulk_insert/bulk_update,而非ORM循环
  • 异步会话使用正确的异步上下文管理器
  • 迁移通过
    downgrade()
    实现可逆
  • 数据迁移使用
    op.execute()
    而非ORM模型
  • 迁移依赖已正确排序

When to Load References

何时查阅参考文档

  • Reviewing session creation/cleanup → sessions.md
  • Reviewing model relationships → relationships.md
  • Reviewing database queries → queries.md
  • Reviewing Alembic migration files → migrations.md
  • 审查会话创建/清理 → sessions.md
  • 审查模型关系 → relationships.md
  • 审查数据库查询 → queries.md
  • 审查Alembic迁移文件 → migrations.md

Review Questions

审查问题

  1. Are all sessions properly managed with context managers?
  2. Are relationships configured to avoid N+1 queries?
  3. Are queries using SQLAlchemy 2.0
    select()
    syntax?
  4. Are all migrations reversible and properly tested?
  1. 所有会话是否都通过上下文管理器正确管理?
  2. 关系配置是否避免了N+1查询?
  3. 查询是否使用SQLAlchemy 2.0的
    select()
    语法?
  4. 所有迁移是否可逆且经过正确测试?