Coverage for docs_src/tutorial/create_db_and_table/tutorial002.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
1from typing import Optional 1abcdef
3from sqlmodel import Field, SQLModel, create_engine 1abcdef
6class Hero(SQLModel, table=True): 1abcdef
7 id: Optional[int] = Field(default=None, primary_key=True) 1abcdef
8 name: str 1abcdef
9 secret_name: str 1abcdef
10 age: Optional[int] = None 1abcdef
13sqlite_file_name = "database.db" 1abcdef
14sqlite_url = f"sqlite:///{sqlite_file_name}" 1abcdef
16engine = create_engine(sqlite_url, echo=True) 1abcdef
19def create_db_and_tables(): 1abcdef
20 SQLModel.metadata.create_all(engine) 1abcdef
23if __name__ == "__main__": 1abcdef
24 create_db_and_tables()