Fixed syntax errors

This commit is contained in:
Hannah dagemark 2026-08-06 22:54:23 +02:00
commit c63bd7a9ee

View file

@ -1,3 +1,4 @@
from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlmodel import Session, SQLModel, create_engine, select
from app.config import settings
@ -19,7 +20,7 @@ def add_to_database(input: SQLModel):
session.commit()
def get_from_database(query: type[SQLModel]) -> list[SQLModel]:
def get_from_database(query: type[SQLModel]):
with Session(engine) as session:
results = session.exec(select(query)).all()
return results
@ -32,7 +33,7 @@ def get_from_database_where(
first_only: bool = False,
offset: int | None = None,
limit: int | None = None,
) -> list[SQLModel]:
):
with Session(engine) as session:
statement = select(query).where(variable == value)
if offset:
@ -58,7 +59,7 @@ def get_from_database_where_id(
def get_from_database_where_join_filter(
query: type[SQLModel],
joined: SQLModel,
joined: type[SQLModel],
variable: object,
value: int | str | None,
):
@ -69,11 +70,11 @@ def get_from_database_where_join_filter(
def get_and_join_from_database(
query: type[SQLModel],
joined: SQLModel,
joined: type[SQLModel],
isouter: bool = False,
):
with Session(engine) as session:
results = session.exec(select(query, joined).join(joined, isouter)).all()
results = session.exec(select(query, joined).join(joined, isouter=isouter))
return results
@ -81,14 +82,14 @@ def update_database_where(
query: type[SQLModel],
variable: object,
value: int | str | None,
attribute: object,
attribute: InstrumentedAttribute[SQLModel],
new_value: int | str | None,
):
with Session(engine) as session:
results = session.exec(select(query).where(variable == value))
results = list(session.exec(select(query).where(variable == value)))
for instance in results:
instance.setAttribute(attribute, new_value)
setattr(instance, attribute.key, new_value)
session.add(instance)
session.commit()
session.refresh(instance)
@ -107,14 +108,5 @@ def delete_from_database_where(
session.delete(instance)
session.commit()
remainder = session.exec(select(query).where(variable == value))
if remainder is None:
return {
"message": "Successfully deleted matching query(ies)",
"deleted": results.all(),
}
else:
return {
"message": "Failed to delete all matching queries",
"remaining": remainder.all(),
}
remainder = session.exec(select(query).where(variable == value)).all()
return remainder