Added update project route and logic

This commit is contained in:
Hannah dagemark 2026-08-06 23:43:22 +02:00
commit 4fc1f58f30
3 changed files with 52 additions and 7 deletions

View file

@ -1,4 +1,3 @@
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlmodel import Session, SQLModel, create_engine, select
from app.config import settings
@ -82,16 +81,19 @@ def update_database_where(
query: type[SQLModel],
variable: object,
value: int | str | None,
attribute: InstrumentedAttribute[SQLModel],
attribute: str,
new_value: int | str | None,
):
with Session(engine) as session:
results = list(session.exec(select(query).where(variable == value)))
for instance in results:
setattr(instance, attribute.key, new_value)
setattr(instance, attribute, new_value)
session.add(instance)
session.commit()
session.commit()
for instance in results:
session.refresh(instance)
return results