|
1 | 1 | """ """ |
2 | 2 |
|
3 | | -from typing import Type |
4 | | - |
5 | 3 | from dateutil.parser import parse as date_parse |
6 | 4 | from dotenv import load_dotenv |
7 | 5 | from sqlalchemy.exc import MultipleResultsFound |
@@ -46,7 +44,7 @@ async def get_result_from_query(query: SelectOfScalar, session: AsyncSession): |
46 | 44 | async def get_one_or_create( |
47 | 45 | session_inst: AsyncSession, |
48 | 46 | model: type[SQLModel], |
49 | | - create_method_kwargs: dict = None, |
| 47 | + create_method_kwargs: dict | None = None, |
50 | 48 | selectin: bool = False, |
51 | 49 | select_in_key: str | None = None, |
52 | 50 | **kwargs, |
@@ -92,12 +90,12 @@ async def _get_entry(sqlmodel, **key_args): |
92 | 90 | return created, False |
93 | 91 |
|
94 | 92 |
|
95 | | -async def write_row(data_row: Type[SQLModel], session_inst: AsyncSession): |
| 93 | +async def write_row(data_row: SQLModel, session_inst: AsyncSession): |
96 | 94 | """ |
97 | 95 | Writes a new instance of an SQLModel ORM model to the database, with an |
98 | 96 | exception catch that rolls back the session in the event of failure. |
99 | 97 |
|
100 | | - :param data_row: Type[SQLModel] |
| 98 | + :param data_row: SQLModel |
101 | 99 | :param session_inst: AsyncSession |
102 | 100 | :return: Tuple[bool, ScalarResult] |
103 | 101 | """ |
@@ -158,7 +156,7 @@ async def insert_data_rows(data_rows, session_inst: AsyncSession): |
158 | 156 |
|
159 | 157 |
|
160 | 158 | async def get_row( |
161 | | - id_str: str or int, |
| 159 | + id_str: str | int, |
162 | 160 | session_inst: AsyncSession, |
163 | 161 | model: type[SQLModel], |
164 | 162 | selectin: bool = False, |
@@ -441,7 +439,7 @@ async def get_rows_within_id_list( |
441 | 439 |
|
442 | 440 |
|
443 | 441 | async def delete_row( |
444 | | - id_str: str or int, |
| 442 | + id_str: str | int, |
445 | 443 | session_inst: AsyncSession, |
446 | 444 | model: type[SQLModel], |
447 | 445 | pk_field: str = "id", |
@@ -498,7 +496,7 @@ async def bulk_upsert_mappings( |
498 | 496 | index_elements=[getattr(model, x) for x in pk_fields], |
499 | 497 | set_={k: getattr(stmnt.excluded, k) for k in payload[0].keys()}, |
500 | 498 | ) |
501 | | - await session_inst.execute(stmnt) |
| 499 | + await session_inst.exec(stmnt) |
502 | 500 |
|
503 | 501 | results = await session_inst.scalars( |
504 | 502 | stmnt.returning(model), execution_options={"populate_existing": True} |
|
0 commit comments