Skip to content

Commit

Permalink
Merge pull request #811 from hotosm/feat-updateSchemas
Browse files Browse the repository at this point in the history
raw sql query wrapped inside text of sqlalchemy
  • Loading branch information
nrjadkry authored Sep 7, 2023
2 parents 0f2f0dd + 61b6762 commit ca99c1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ def get_task_geometry(db: Session, project_id: int):
async def get_project_features_geojson(db:Session, project_id:int):

# Get the geojson of those features for this task.
query = f"""SELECT jsonb_build_object(
query = text(f"""SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
Expand All @@ -1563,7 +1563,7 @@ async def get_project_features_geojson(db:Session, project_id:int):
FROM features
WHERE project_id={project_id}
) features;
"""
""")

result = db.execute(query)
features = result.fetchone()[0]
Expand Down Expand Up @@ -2088,20 +2088,20 @@ async def update_project_form(
# Get the features for this task.
# Postgis query to filter task inside this task outline and of this project
# Update those features and set task_id
query = f"""UPDATE features
query = text(f"""UPDATE features
SET task_id={task}
WHERE id in (
SELECT id
FROM features
WHERE project_id={project_id} and ST_Intersects(geometry, '{task_obj.outline}'::Geometry)
)"""
)""")

result = db.execute(query)

# Get the geojson of those features for this task.
query = f"""SELECT jsonb_build_object(
query = text(f"""SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
Expand All @@ -2114,7 +2114,7 @@ async def update_project_form(
) AS feature
FROM features
WHERE project_id={project_id} and task_id={task}
) features;"""
) features;""")

result = db.execute(query)
features = result.fetchone()[0]
Expand Down Expand Up @@ -2154,7 +2154,7 @@ async def update_odk_credentials(

async def get_extracted_data_from_db(db: Session, project_id: int, outfile: str):
"""Get the geojson of those features for this project."""
query = f"""SELECT jsonb_build_object(
query = text(f"""SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
Expand All @@ -2167,7 +2167,7 @@ async def get_extracted_data_from_db(db: Session, project_id: int, outfile: str)
) AS feature
FROM features
WHERE project_id={project_id}
) features;"""
) features;""")

result = db.execute(query)
features = result.fetchone()[0]
Expand Down Expand Up @@ -2208,7 +2208,7 @@ def get_project_tiles(
db.commit()

# Project Outline
query = f"""SELECT jsonb_build_object(
query = text(f"""SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
Expand All @@ -2220,7 +2220,7 @@ def get_project_tiles(
) AS feature
FROM projects
WHERE id={project_id}
) features;"""
) features;""")

result = db.execute(query)
features = result.fetchone()[0]
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/tasks/tasks_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


async def get_task_count_in_project(db: Session, project_id: int):
query = f"""select count(*) from tasks where project_id = {project_id}"""
query = text(f"""select count(*) from tasks where project_id = {project_id}""")
result = db.execute(query)
return result.fetchone()[0]

Expand Down

0 comments on commit ca99c1d

Please sign in to comment.