Coverage for docs_src/tutorial/create_db_and_table/tutorial003.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 # (1)! 1abcdef
3from sqlmodel import Field, SQLModel, create_engine # (2)! 1abcdef
6class Hero(SQLModel, table=True): # (3)! 1abcdef
7 id: Optional[int] = Field(default=None, primary_key=True) # (4)! 1abcdef
8 name: str # (5)! 1abcdef
9 secret_name: str # (6)! 1abcdef
10 age: Optional[int] = None # (7)! 1abcdef
13sqlite_file_name = "database.db" # (8)! 1abcdef
14sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)! 1abcdef
16engine = create_engine(sqlite_url, echo=True) # (10)! 1abcdef
19def create_db_and_tables(): # (11)! 1abcdef
20 SQLModel.metadata.create_all(engine) # (12)! 1abcdef
23if __name__ == "__main__": # (13)! 1abcdef
24 create_db_and_tables() # (14)!