from typing import Optional, List
from sqlmodel import (
    SQLModel,
    Field,
    create_engine,
    Relationship
)


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


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

    livros: List['Livro'] = Relationship(back_populates='person')


class Livro(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    titulo: str

    pessoa_id: Optional[int] = Field(default=None, foreign_key='person.id')
    pessoa: Optional[Person] = Relationship(back_populates='livros')


SQLModel.metadata.create_all(engine)
sqlmodel.Relationship sqlmodel.SQLModel.metadata.create_all sqlmodel.create_engine sqlmodel.Field
[((131, 169), 'sqlmodel.create_engine', 'create_engine', (['"""sqlite:///database.db"""'], {}), "('sqlite:///database.db')\n", (144, 169), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((629, 665), 'sqlmodel.SQLModel.metadata.create_all', 'SQLModel.metadata.create_all', (['engine'], {}), '(engine)\n', (657, 665), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((232, 269), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (237, 269), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((328, 365), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""person"""'}), "(back_populates='person')\n", (340, 365), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((427, 464), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'primary_key': '(True)'}), '(default=None, primary_key=True)\n', (432, 464), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((513, 557), 'sqlmodel.Field', 'Field', ([], {'default': 'None', 'foreign_key': '"""person.id"""'}), "(default=None, foreign_key='person.id')\n", (518, 557), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n'), ((589, 626), 'sqlmodel.Relationship', 'Relationship', ([], {'back_populates': '"""livros"""'}), "(back_populates='livros')\n", (601, 626), False, 'from sqlmodel import SQLModel, Field, create_engine, Relationship\n')]