Coverage for docs_src/tutorial/create_db_and_table/tutorial003_py310.py: 100%

11 statements  

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

1from sqlmodel import Field, SQLModel, create_engine # (2)! 1abc

2 

3 

4class Hero(SQLModel, table=True): # (3)! 1abc

5 id: int | None = Field(default=None, primary_key=True) # (4)! 1abc

6 name: str # (5)! 1abc

7 secret_name: str # (6)! 1abc

8 age: int | None = None # (7)! 1abc

9 

10 

11sqlite_file_name = "database.db" # (8)! 1abc

12sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)! 1abc

13 

14engine = create_engine(sqlite_url, echo=True) # (10)! 1abc

15 

16 

17def create_db_and_tables(): # (11)! 1abc

18 SQLModel.metadata.create_all(engine) # (12)! 1abc

19 

20 

21if __name__ == "__main__": # (13)! 1abc

22 create_db_and_tables() # (14)!