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

15 statements  

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

1from sqlmodel import Session 1abcdef

2 

3from .database import create_db_and_tables, engine 1abcdef

4from .models import Hero, Team 1abcdef

5 

6 

7def create_heroes(): 1abcdef

8 with Session(engine) as session: 1abcdef

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

10 

11 hero_deadpond = Hero( 1abcdef

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

13 ) 

14 session.add(hero_deadpond) 1abcdef

15 session.commit() 1abcdef

16 

17 session.refresh(hero_deadpond) 1abcdef

18 

19 print("Created hero:", hero_deadpond) 1abcdef

20 print("Hero's team:", hero_deadpond.team) 1abcdef

21 

22 

23def main(): 1abcdef

24 create_db_and_tables() 1abcdef

25 create_heroes() 1abcdef

26 

27 

28if __name__ == "__main__": 1abcdef

29 main()