Skip to content

Commit

Permalink
Add return type and move function call out of default parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJBoyer committed May 8, 2024
1 parent 741c5b7 commit 272da42
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/src/db/bulk_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
Cursor = psycopg.Cursor
kwargs_row = rows.kwargs_row

EMPTY_SQL = sql.SQL("")


def bulk_upsert(
cur: psycopg.Cursor,
table: str,
attributes: Sequence[str],
objects: Sequence[Any],
constraint: str,
update_condition: sql.SQL = sql.SQL(""),
):
update_condition: sql.SQL = EMPTY_SQL,
) -> None:
"""Bulk insert or update a sequence of objects.
Insert a sequence of objects, or update on conflict.
Expand Down Expand Up @@ -48,7 +50,7 @@ def bulk_upsert(
)


def create_temp_table(cur: psycopg.Cursor, temp_table: str, src_table: str):
def create_temp_table(cur: psycopg.Cursor, temp_table: str, src_table: str) -> None:
"""
Create table that lives only for the current transaction.
Use an existing table to determine the table structure.
Expand All @@ -74,7 +76,7 @@ def bulk_insert(
table: str,
columns: Sequence[str],
objects: Sequence[Any],
):
) -> None:
"""
Write data from a sequence of objects to a temp table.
This function uses the PostgreSQL COPY command which is highly performant.
Expand All @@ -101,8 +103,8 @@ def write_from_table_to_table(
dest_table: str,
columns: Sequence[str],
constraint: str,
update_condition: sql.SQL = sql.SQL(""),
):
update_condition: sql.SQL = EMPTY_SQL,
) -> None:
"""
Write data from one table to another.
If there are conflicts due to unique constraints, overwrite existing data.
Expand All @@ -122,6 +124,7 @@ def write_from_table_to_table(
column=sql.Identifier(column),
)
for column in columns
if column not in ["id", "number"]
]
)
query = sql.SQL(
Expand Down

0 comments on commit 272da42

Please sign in to comment.