20 lines
638 B
Python
20 lines
638 B
Python
import psycopg2
|
|
|
|
class Database:
|
|
__conn:psycopg2.connect
|
|
__cursor:psycopg2.cursor
|
|
|
|
def __init__(self, database:str, host:str, user:str, password:str, port:str):
|
|
self.__conn = psycopg2.connect(database=database, host=host, user=user, password=password, port=port)
|
|
self.__cursor = self.__conn.cursor()
|
|
|
|
def getConnection(self) -> psycopg2.connect:
|
|
return self.__conn
|
|
|
|
def fetchall(self, query:str):
|
|
self.__cursor.execute(query)
|
|
return self.__cursor.fetchall()
|
|
|
|
def fetchone(self, query:str):
|
|
self.__cursor.execute(query)
|
|
return self.__cursor.fetchone() |