Coverage for docs_src/tutorial/create_db_and_table/tutorial001.py: 0%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from typing import Optional 

2 

3from sqlmodel import Field, SQLModel, create_engine 

4 

5 

6class Hero(SQLModel, table=True): 

7 id: Optional[int] = Field(default=None, primary_key=True) 

8 name: str 

9 secret_name: str 

10 age: Optional[int] = None 

11 

12 

13sqlite_file_name = "database.db" 

14sqlite_url = f"sqlite:///{sqlite_file_name}" 

15 

16engine = create_engine(sqlite_url, echo=True) 

17 

18SQLModel.metadata.create_all(engine)