You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
869 B
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from utils import *
def get_products() -> list[dict]:
connection = None
cursor = None
res = None
try:
connection = psycopg2.connect(**DB_CONFIG)
cursor = connection.cursor()
res = fetch_table_as_json(cursor, "shop")
except psycopg2.Error as e:
print("Ошибка при работе с PostgreSQL:", e)
finally:
cursor.close()
connection.close()
return res
def get_product(product_id: int):
connection = None
cursor = None
res = None
try:
connection = psycopg2.connect(**DB_CONFIG)
cursor = connection.cursor()
res = fetch_row_as_json(cursor, "shop", product_id)
except psycopg2.Error as e:
print("Ошибка при работе с PostgreSQL:", e)
finally:
cursor.close()
connection.close()
return res