Coverage for docs_src/tutorial/code_structure/tutorial002_py39/app.py: 100%

16 statements  

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

1from sqlmodel import Session 1abcd

2 

3from .database import create_db_and_tables, engine 1abcd

4from .hero_model import Hero 1abcd

5from .team_model import Team 1abcd

6 

7 

8def create_heroes(): 1abcd

9 with Session(engine) as session: 1abcd

10 team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") 1abcd

11 

12 hero_deadpond = Hero( 1abcd

13 name="Deadpond", secret_name="Dive Wilson", team=team_z_force 

14 ) 

15 session.add(hero_deadpond) 1abcd

16 session.commit() 1abcd

17 

18 session.refresh(hero_deadpond) 1abcd

19 

20 print("Created hero:", hero_deadpond) 1abcd

21 print("Hero's team:", hero_deadpond.team) 1abcd

22 

23 

24def main(): 1abcd

25 create_db_and_tables() 1abcd

26 create_heroes() 1abcd

27 

28 

29if __name__ == "__main__": 1abcd

30 main()