add insUser + insChat

This commit is contained in:
ada-dmitry
2023-08-22 15:16:49 +03:00
parent 3e6834ed87
commit 767468da74
+14 -9
View File
@@ -11,29 +11,29 @@ db_params = {
connection = psycopg2.connect(**db_params) connection = psycopg2.connect(**db_params)
cursor = connection.cursor() cursor = connection.cursor()
def query_ins_user(str x): def query_ins_user(str x, curs = cursor):
try: try:
# Запрос добавления пользователя # Запрос добавления пользователя
cursor.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""") curs.execute(f"""INSERT into public.Users(TrueUserID, role, isAlive) values ({x}, 0)""")
cursor.commit() curs.commit()
except Exception as e: except Exception as e:
print("Ошибка:", e) print("Ошибка:", e)
def query_ins_chat(str x): def query_ins_chat(str x, curs = cursor):
try: # Запрос добавления чата try: # Запрос добавления чата
cursor.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""") curs.execute(f"""INSERT into public.Chats(TrueChatID, StateID) values ({x}, 0)""")
cursor.commit() curs.commit()
except Exception as e: except Exception as e:
print("Ошибка:", e) print("Ошибка:", e)
def query_sel(str x): def query_sel(str x, curs = cursor):
try: try:
# Запрос вывода из БД # Запрос вывода из БД
cursor.execute("SELECT * FROM chats") curs.execute("SELECT * FROM chats")
rows = cursor.fetchall() rows = curs.fetchall()
# for row in rows: # for row in rows:
# print(row) # print(row)
@@ -41,6 +41,11 @@ def query_sel(str x):
except Exception as e: except Exception as e:
print("Ошибка:", e) print("Ошибка:", e)
def query_change(str x):
# Написать выдачу резов по ролям
def close(cur = cursor, conn = connection): def close(cur = cursor, conn = connection):
cursor.close() cursor.close()
connection.close() connection.close()