from typing import Optional
from fastapi import FastAPI
from sqlalchemy.sql.expression import table
from sqlmodel import (
    SQLModel,
    Field,
    create_engine,
    select,
    Session

)

engine = create_engine('sqlite:///database.db')

class Pessoa(SQLModel, table=True):
    id : Optional[int] = Field(default=None, primary_key=True)
    nome: str
    idade: str

SQLModel.metadata.create_all(engine)

app = FastAPI()

@app.get('/')
def home():
    return {'message' : 'Deu bom!!!'}

@app.get('/pessoa')
def pessoa():
    query = select(Pessoa)
    with Session(engine) as session:
        result = session.execute(query).scalars().all()
    return result

@app.get('/pessoas-nome')
def pessoa():
    query = select(Pessoa.nome)
    with Session(engine) as session:
        result = session.execute(query).scalars().all()
    return result

fastapi.FastAPI sqlmodel.create_engine sqlmodel.select sqlmodel.Session sqlmodel.SQLModel.metadata.create_all sqlmodel.Field
[((204, 242), 'sqlmodel.create_engine', 'create_engine', (['"""sqlite:///database.db"""'], {}), "('sqlite:///database.db')\n", (217, 242), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((373, 409), 'sqlmodel.SQLModel.metadata.create_all', 'SQLModel.metadata.create_all', (['engine'], {}), '(engine)\n', (401, 409), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((417, 426), 'fastapi.FastAPI', 'FastAPI', ([], {}), '()\n', (424, 426), False, 'from fastapi import FastAPI\n'), ((305, 342), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (310, 342), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((539, 553), 'sqlmodel.select', 'select', (['Pessoa'], {}), '(Pessoa)\n', (545, 553), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((718, 737), 'sqlmodel.select', 'select', (['Pessoa.nome'], {}), '(Pessoa.nome)\n', (724, 737), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((563, 578), 'sqlmodel.Session', 'Session', (['engine'], {}), '(engine)\n', (570, 578), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n'), ((747, 762), 'sqlmodel.Session', 'Session', (['engine'], {}), '(engine)\n', (754, 762), False, 'from sqlmodel import SQLModel, Field, create_engine, select, Session\n')]