Skip to content

Commit 1620e63

Browse files
author
Edward Keeble
committed
Support method parameter on bulk transactions route to allow upserting bulk data
1 parent 9692f1e commit 1620e63

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

stac_fastapi/pgstac/transactions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from stac_fastapi.extensions.third_party.bulk_transactions import (
1111
AsyncBaseBulkTransactionsClient,
1212
Items,
13+
BulkTransactionMethod,
1314
)
1415
from stac_fastapi.types import stac as stac_types
1516
from stac_fastapi.types.core import AsyncBaseTransactionsClient
@@ -178,11 +179,17 @@ async def delete_collection(
178179
class BulkTransactionsClient(AsyncBaseBulkTransactionsClient):
179180
"""Postgres bulk transactions."""
180181

181-
async def bulk_item_insert(self, items: Items, request: Request, **kwargs) -> str:
182+
async def bulk_item_insert(
183+
self, items: Items, request: Request, method: BulkTransactionMethod, **kwargs
184+
) -> str:
182185
"""Bulk item insertion using pgstac."""
183186
items = list(items.items.values())
187+
184188
async with request.app.state.get_connection(request, "w") as conn:
185-
await dbfunc(conn, "create_items", items)
189+
if method == BulkTransactionMethod.INSERT:
190+
await dbfunc(conn, "create_items", items)
191+
elif method == BulkTransactionMethod.UPSERT:
192+
await dbfunc(conn, "upsert_items", items)
186193

187194
return_msg = f"Successfully added {len(items)} items."
188195
return return_msg

0 commit comments

Comments
 (0)