Skip to content

Issue trying to use SQLModel with AsyncSession and object conversion from Row #1472

Answered by YuriiMotov
Miguelme asked this question in Questions
Discussion options

You must be logged in to vote

You just need to import select from SQLModel instead of sqlalchemy:

from typing import Optional

from fastapi import Depends, FastAPI
from sqlalchemy import StaticPool
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import selectinload, sessionmaker
from sqlmodel import Field, SQLModel, select
from sqlmodel.ext.asyncio.session import AsyncSession

engine = create_async_engine(
    "sqlite+aiosqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession)


async def get_db():
    async with SessionLocal() as session:
        yield session

class Item(SQ…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies

This comment has been hidden.

Comment options

You must be logged in to vote
0 replies

This comment has been hidden.

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants
Converted from issue

This discussion was converted from issue #378 on August 08, 2025 15:47.