From 60661d41da0e18b3b8405e15b2af96f285c05460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Hu=CC=88hne?= Date: Mon, 24 Jun 2024 09:35:23 +0200 Subject: [PATCH] Update SQLAlchemy and related dependencies --- app/crud.py | 13 +++++++------ app/database.py | 3 +-- requirements.txt | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/crud.py b/app/crud.py index 0bacbe7..65d3374 100644 --- a/app/crud.py +++ b/app/crud.py @@ -1,6 +1,7 @@ from typing import List, Optional from sqlalchemy.orm import Session +from sqlalchemy.sql import text from . import models from .filters import SchoolFilter @@ -26,26 +27,26 @@ def get_schools(db: Session, skip: int = 0, limit: int = 100, filter_params=None def get_stats(db: Session): - response = db.execute("""select substring(id, 1, 2) as state, count(*) as count + response = db.execute(text("""select substring(id, 1, 2) as state, count(*) as count from schools group by state -order by state;""") - return list(response) +order by state;""")) + return [row._mapping for row in response] def _get_states(db: Session): - return [state for state, in db.execute("select distinct(substring(id, 1, 2)) from schools;")] + return [state for state, in db.execute(text("select distinct(substring(id, 1, 2)) from schools;"))] def _get_school_types(db: Session): return [school_type for school_type, in - db.execute("select distinct(school_type) from schools where school_type is not null;") + db.execute(text("select distinct(school_type) from schools where school_type is not null;")) ] def _get_legal_status(db: Session): return [school_type for school_type, in - db.execute("select distinct(legal_status) from schools where legal_status is not null;") + db.execute(text("select distinct(legal_status) from schools where legal_status is not null;")) ] diff --git a/app/database.py b/app/database.py index a6444b0..07098c0 100644 --- a/app/database.py +++ b/app/database.py @@ -1,8 +1,7 @@ import os from sqlalchemy import create_engine -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import sessionmaker, declarative_base engine = create_engine(os.environ.get("DATABASE_URL")) diff --git a/requirements.txt b/requirements.txt index 14ef5a5..7840bc6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ fastapi==0.65.2 -GeoAlchemy2==0.8.4 -psycopg2==2.8.4 +GeoAlchemy2==0.15.1 +psycopg2==2.9.9 Shapely==1.7.1 -SQLAlchemy==1.3.10 +SQLAlchemy==2.0.31