Skip to content

Commit

Permalink
fix: avoid f-string in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach authored and gadomski committed May 11, 2023
1 parent f9570d2 commit 3ed39ca
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions stac_fastapi/pgstac/db.py
Expand Up @@ -7,7 +7,7 @@
import attr
import orjson
from asyncpg import exceptions, pool
from buildpg import asyncpg, render
from buildpg import V, asyncpg, render
from fastapi import FastAPI
from stac_fastapi.types.errors import (
ConflictError,
Expand Down Expand Up @@ -65,18 +65,20 @@ async def dbfunc(pool: pool, func: str, arg: Union[str, Dict]):
if isinstance(arg, str):
async with pool.acquire() as conn:
q, p = render(
f"""
SELECT * FROM {func}(:item::text);
"""
SELECT * FROM :func(:item::text);
""",
func=V(func),
item=arg,
)
return await conn.fetchval(q, *p)
else:
async with pool.acquire() as conn:
q, p = render(
f"""
SELECT * FROM {func}(:item::text::jsonb);
"""
SELECT * FROM :func(:item::text::jsonb);
""",
func=V(func),
item=json.dumps(arg),
)
return await conn.fetchval(q, *p)
Expand Down

0 comments on commit 3ed39ca

Please sign in to comment.