24 lines
619 B
Python
24 lines
619 B
Python
|
|
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
|