You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question 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
def create_one(entity: Role) -> Role:
with datastore_utility.create_session() as session:
try:
session.add(entity)
session.commit()
session.refresh(entity)
except Exception as e:
raise e
return entity
def delete_one_by_id(id: UUID) -> Role:
with datastore_utility.create_session() as session:
try:
statement: expression = select(Role).where(Role.id == id)
found_entity: Role = session.exec(statement).first()
if found_entity is None:
raise Exception("Entity not found.")
session.delete(found_entity)
session.commit()
session.refresh(found_entity)
except Exception as e:
raise e
return found_entity
Description
As a Developer, I want to reuse the SQLModel object by deleting and recreating the object to the database so that I can use the object in an easy way for each re-operations.
Reuse operations are needed when using it in setup and teardown testing operations.
The solution that I can think of is, we try using a flag variable in the model if it got deleted or not. When it got refreshed again, we can replace the old info value in the object with the new one.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Operating System
Linux, Windows
Operating System Details
No response
SQLModel Version
0.08
Python Version
Python 3.9.16
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions