123456789101112131415161718192021222324 |
- from sqlmodel import SQLModel, Field, create_engine
- engine = create_engine(
- 'sqlite:///db.sqlite',
- echo=True,
- connect_args={
- 'check_same_thread': False
- }
- )
- class Hero(SQLModel, table=True):
- id: int | None = Field(default=None, primary_key=True)
- name: str
- secret_name: str
- age: int | None = None
- @property
- def full_name(self) -> str:
- return f'{self.name} ({self.secret_name})'
- def create_tables(engine):
- SQLModel.metadata.create_all(engine)
|