Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions stac_fastapi/pgstac/db.py
Original file line number Diff line number Diff line change
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