fastapi-sqlmodel-alembic
fastapi-sqlmodel-alembic copied to clipboard
Why is there a extra step to recreate objects?
I wonder if
@app.get("/songs", response_model=list[Song])
async def get_songs(session: AsyncSession = Depends(get_session)):
result = await session.execute(select(Song))
return result.scalars().all()
wouldn't be the same but shorter then
@app.get("/songs", response_model=list[Song])
async def get_songs(session: AsyncSession = Depends(get_session)):
result = await session.execute(select(Song))
songs = result.scalars().all()
return [Song(name=song.name, artist=song.artist, year=song.year, id=song.id) for song in songs]
or is it necessary to create the new models for some reason?