Skip to content

Conversation

@shuteng8787-sudo
Copy link

Add Documentation for Async SQLModel Usage

Description

This PR adds comprehensive documentation for using SQLModel with async and await, resolving Issue #626.

Although SQLModel has had AsyncSession support for some time, it was not documented in the official tutorial or user guide. This PR addresses that by adding a new tutorial section dedicated to asynchronous usage.

Changes

Documentation

  • Created docs/tutorial/async/index.md: A new tutorial page covering:
    • Asynchronous engine configuration with create_async_engine.
    • Using aiosqlite for asynchronous SQLite support.
    • Basic usage of AsyncSession and the exec() method.
    • Integration with FastAPI using async dependencies.
    • Common pitfalls and best practices (e.g., lazy loading, eager loading with selectinload).
  • Updated docs/advanced/index.md to link to the new async tutorial.
  • Updated mkdocs.yml to include the new tutorial in the navigation under the Advanced User Guide.

Source Code Examples

  • Created docs_src/tutorial/async/:
    • tutorial001_py310.py: Modern Python 3.10+ async example.
    • tutorial001_py39.py: Python 3.9 async example.
    • tutorial001.py: Baseline async example.

Library Improvements

  • Updated sqlmodel/ext/asyncio/__init__.py to export AsyncSession, allowing for cleaner imports:
    from sqlmodel.ext.asyncio import AsyncSession

Related Issues

Fixes #626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add documentation about how to use the async tools (session, etc)

1 participant