From 29ceb95404c276c7d4c694b2976a8f2cac8b1771 Mon Sep 17 00:00:00 2001 From: T-BENZIN Date: Sat, 27 May 2023 16:17:29 +0500 Subject: [PATCH] Added db.py in which the PostgreSQLDatabase class were added for working with DB. --- db.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 db.py diff --git a/db.py b/db.py new file mode 100644 index 0000000..2f9aee6 --- /dev/null +++ b/db.py @@ -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