Added db.py in which the PostgreSQLDatabase class were added for working with DB.
This commit is contained in:
parent
9924f0eebb
commit
29ceb95404
23
db.py
Normal file
23
db.py
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user