From: Yurii Motov Date: Wed, 24 Dec 2025 21:59:58 +0000 (+0100) Subject: Update `docs_src/tutorial/relationship_attributes` X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29554804df8a2504e00f59884db99798b2fbb0e5;p=thirdparty%2Ffastapi%2Fsqlmodel.git Update `docs_src/tutorial/relationship_attributes` --- diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py deleted file mode 100644 index 39230cb6..00000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py +++ /dev/null @@ -1,143 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship() - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship() - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - - preventers_team = session.exec( - select(Team).where(Team.name == "Preventers") - ).one() - - print("Hero Spider-Boy:", hero_spider_boy) - print("Preventers Team:", preventers_team) - print("Preventers Team Heroes:", preventers_team.heroes) - - hero_spider_boy.team = None - - print("Spider-Boy without team:", hero_spider_boy) - - print("Preventers Team Heroes again:", preventers_team.heroes) - - session.add(hero_spider_boy) - session.commit() - print("After committing") - - session.refresh(hero_spider_boy) - print("Spider-Boy after commit:", hero_spider_boy) - - print("Preventers Team Heroes after commit:", preventers_team.heroes) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py deleted file mode 100644 index a1add4bc..00000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py +++ /dev/null @@ -1,143 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - - preventers_team = session.exec( - select(Team).where(Team.name == "Preventers") - ).one() - - print("Hero Spider-Boy:", hero_spider_boy) - print("Preventers Team:", preventers_team) - print("Preventers Team Heroes:", preventers_team.heroes) - - hero_spider_boy.team = None - - print("Spider-Boy without team:", hero_spider_boy) - - print("Preventers Team Heroes again:", preventers_team.heroes) - - session.add(hero_spider_boy) - session.commit() - print("After committing") - - session.refresh(hero_spider_boy) - print("Spider-Boy after commit:", hero_spider_boy) - - print("Preventers Team Heroes after commit:", preventers_team.heroes) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py deleted file mode 100644 index 98e19700..00000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py +++ /dev/null @@ -1,59 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, SQLModel, create_engine - - -class Weapon(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - - hero: "Hero" = Relationship(back_populates="weapon") - - -class Power(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - - hero_id: int = Field(foreign_key="hero.id") - hero: "Hero" = Relationship(back_populates="powers") - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - weapon_id: Optional[int] = Field(default=None, foreign_key="weapon.id") - weapon: Optional[Weapon] = Relationship(back_populates="hero") - - powers: List[Power] = Relationship(back_populates="hero") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def main(): - create_db_and_tables() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py deleted file mode 100644 index 877aeb3c..00000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py +++ /dev/null @@ -1,110 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", cascade_delete=True) - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="CASCADE" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion not found:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E not found:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py deleted file mode 100644 index ac97a20f..00000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py +++ /dev/null @@ -1,110 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="SET NULL" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py deleted file mode 100644 index 0424f756..00000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py +++ /dev/null @@ -1,112 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="SET NULL" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py deleted file mode 100644 index 00c5ac17..00000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py +++ /dev/null @@ -1,111 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="RESTRICT" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py deleted file mode 100644 index b46a7781..00000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py +++ /dev/null @@ -1,124 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="RESTRICT" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def remove_team_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - team.heroes.clear() - session.add(team) - session.commit() - session.refresh(team) - print("Team with removed heroes:", team) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - remove_team_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py deleted file mode 100644 index 73c68cf9..00000000 --- a/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py +++ /dev/null @@ -1,102 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def main(): - create_db_and_tables() - create_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py b/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py deleted file mode 100644 index af218b95..00000000 --- a/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py +++ /dev/null @@ -1,70 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - - -def main(): - create_db_and_tables() - create_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py deleted file mode 100644 index b8bbe70a..00000000 --- a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py +++ /dev/null @@ -1,117 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Spider-Boy") - result = session.exec(statement) - hero_spider_boy = result.one() - - statement = select(Team).where(Team.id == hero_spider_boy.team_id) - result = session.exec(statement) - team = result.first() - print("Spider-Boy's team:", team) - - print("Spider-Boy's team again:", hero_spider_boy.team) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py b/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py deleted file mode 100644 index 30fa8408..00000000 --- a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py +++ /dev/null @@ -1,127 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Spider-Boy") - result = session.exec(statement) - hero_spider_boy = result.one() - - hero_spider_boy.team = None - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_spider_boy) - print("Spider-Boy without team:", hero_spider_boy) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py index 698a7af2..208cfb7c 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py @@ -5,14 +5,13 @@ import pytest from sqlalchemy.exc import SAWarning from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py index 8ce54be4..65a849f2 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py index d30c71c3..a23800db 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py @@ -6,14 +6,13 @@ from sqlalchemy import inspect from sqlalchemy.engine.reflection import Inspector from sqlmodel import create_engine -from ....conftest import needs_py39, needs_py310 +from ....conftest import needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", - pytest.param("tutorial003_py39", marks=needs_py39), + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py index 0c6a2291..d73be8f3 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py index 96cf8bcc..516f3e38 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py index 5e43f80c..fddaf3d9 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py index cb3907af..5614c2fe 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py index e063630f..095062d7 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", - pytest.param("tutorial003_py39", marks=needs_py39), + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py index 8b6c101f..fb045d45 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py @@ -5,14 +5,13 @@ import pytest from sqlalchemy.exc import IntegrityError from sqlmodel import Session, create_engine, select -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial004", - pytest.param("tutorial004_py39", marks=needs_py39), + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py index 27300777..d2170f22 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial005", - pytest.param("tutorial005_py39", marks=needs_py39), + pytest.param("tutorial005_py39"), pytest.param("tutorial005_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py index 1b2caaa9..651f44a0 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py index 68ee2cc1..306f3f17 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], )