Skip to content

Best practice for multiple updateΒ #181

@hilmanski

Description

@hilmanski

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options πŸ‘†

Example Code

Example code multiple update data


def update_heroes():
    with Session(engine) as session:
         statement = select(Hero).where(Hero.name == "Spider-Boy")  # 
        results = session.exec(statement)  # 
        hero_1 = results.one()  # 
        print("Hero 1:", hero_1)  # 
        statement = select(Hero).where(Hero.name == "Captain North America")  # 
        results = session.exec(statement)  #         
        hero_2 = results.one()  # 
 .....

Description

Based on the documentation, when we want to update multiple data. We need to do N+1 query:
doc multiple update

Are there any other way to do it with only select needed data once?

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.9

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    answeredquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions