Added db.py in which the PostgreSQLDatabase class were added for working with DB.

This commit is contained in:
T-BENZIN 2023-05-27 16:17:29 +05:00
parent 9924f0eebb
commit 29ceb95404

23
db.py Normal file
View File

@ -0,0 +1,23 @@
import psycopg2
class PostgreSQLDatabase:
def __init__(self, host, database, user, password):
self.__host = host
self.__database = database
self.__user = user
self.__password = password
def execute_query(self, query):
connection = psycopg2.connect(
host=self.__host,
database=self.__database,
user=self.__user,
password=self.__password
)
cursor = connection.cursor()
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
connection.close()
return result