1- """ Common functions to access products table
2-
3- """
1+ """Common functions to access products table"""
42
53import warnings
64
75import sqlalchemy as sa
6+ from aiopg .sa .connection import SAConnection
7+ from sqlalchemy .ext .asyncio import AsyncConnection
88
9- from ._protocols import AiopgConnection , DBConnection
109from .models .groups import GroupType , groups
1110from .models .products import products
1211
1312# NOTE: outside this module, use instead packages/models-library/src/models_library/users.py
1413_GroupID = int
1514
1615
17- async def get_default_product_name (conn : DBConnection ) -> str :
16+ async def get_default_product_name (conn : AsyncConnection | SAConnection ) -> str :
1817 """The first row in the table is considered as the default product
1918
2019 :: raises ValueError if undefined
@@ -31,15 +30,17 @@ async def get_default_product_name(conn: DBConnection) -> str:
3130
3231
3332async def get_product_group_id (
34- connection : DBConnection , product_name : str
33+ connection : SAConnection , product_name : str
3534) -> _GroupID | None :
3635 group_id = await connection .scalar (
3736 sa .select (products .c .group_id ).where (products .c .name == product_name )
3837 )
3938 return None if group_id is None else _GroupID (group_id )
4039
4140
42- async def execute_get_or_create_product_group (conn , product_name : str ) -> int :
41+ async def execute_get_or_create_product_group (
42+ conn : AsyncConnection , product_name : str
43+ ) -> int :
4344 #
4445 # NOTE: Separated so it can be used in asyncpg and aiopg environs while both
4546 # coexist
@@ -73,7 +74,7 @@ async def execute_get_or_create_product_group(conn, product_name: str) -> int:
7374
7475
7576async def get_or_create_product_group (
76- connection : AiopgConnection , product_name : str
77+ connection : SAConnection , product_name : str
7778) -> _GroupID :
7879 """
7980 Returns group_id of a product. Creates it if undefined
0 commit comments