From 9e9391f3161de1fdd87c736e296b0522e9c98c6c Mon Sep 17 00:00:00 2001 From: Marc Sune Date: Wed, 12 Jun 2024 23:48:23 +0200 Subject: [PATCH] Tc --- src/routes/turnilo_dashboard_routes.py | 2 +- src/services/turnilo_dashboards.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/routes/turnilo_dashboard_routes.py b/src/routes/turnilo_dashboard_routes.py index 2dcce71..cbd8a66 100644 --- a/src/routes/turnilo_dashboard_routes.py +++ b/src/routes/turnilo_dashboard_routes.py @@ -1,7 +1,7 @@ import re from fastapi import APIRouter, Depends, HTTPException, Query from typing import List -from sqlalchemy.orm import Session +from sqlmodel import Session from models.turnilo_dashboard import TurniloDashboard from services import turnilo_dashboards as td diff --git a/src/services/turnilo_dashboards.py b/src/services/turnilo_dashboards.py index 790a8ca..4a27961 100644 --- a/src/services/turnilo_dashboards.py +++ b/src/services/turnilo_dashboards.py @@ -1,5 +1,5 @@ from typing import List -from sqlalchemy.orm import Session +from sqlmodel import Session, select from sqlalchemy import exc from models.turnilo_dashboard import TurniloDashboard from fastapi import HTTPException @@ -8,12 +8,12 @@ def dashboards_get_all(session: Session, shortName: str, dataCube: str) -> List[TurniloDashboard]: - query = session.query(TurniloDashboard) + statement = select(TurniloDashboard) if shortName: - query = query.filter(TurniloDashboard.shortName == shortName) + statement = statement.where(TurniloDashboard.shortName == shortName) if dataCube: - query = query.filter(TurniloDashboard.dataCube == dataCube) - return query.all() + statement = statement.where(TurniloDashboard.dataCube == dataCube) + return list(session.exec(statement).all()) def _dashboards_return_single_obj(results: List[TurniloDashboard]): @@ -25,7 +25,8 @@ def _dashboards_return_single_obj(results: List[TurniloDashboard]): def dashboards_get_id(session: Session, _id: int) -> TurniloDashboard: - results: List[TurniloDashboard] = session.query(TurniloDashboard).filter_by(id=_id).all() + statement = select(TurniloDashboard).where(TurniloDashboard.id == _id) + results: List[TurniloDashboard] = list(session.exec(statement).all()) return _dashboards_return_single_obj(results) @@ -67,7 +68,8 @@ def dashboards_update(session: Session, dashboard: TurniloDashboard) -> TurniloD def dashboards_delete(session: Session, _id: int) -> TurniloDashboard: dashboard = None try: - dashboard = session.query(TurniloDashboard).filter_by(id=_id).one() + statement = select(TurniloDashboard).where(TurniloDashboard.id == _id) + dashboard = session.exec(statement).one() except BaseException: pass if dashboard is None: