import mariadb
import os

'''

Trida pro komunikaci s databazi

'''

class DatabaseHandler():
    def __init__(self):
        self.mydb = mariadb.connect(
        host=os.environ.get('DB_HOST') or "localhost",
        user=os.environ.get('DB_USER') or "root",
        password=os.environ.get('DB_PASSWORD') or "",
        port=int(os.environ.get('DB_PORT') or 3308),
        database=os.environ.get('DB_DATABASE') or "zmb_hlasovani"
        )

        self.cursor = self.mydb.cursor(buffered=True)

    def commitStatement(self):
        self.mydb.commit()

    def closeConnection(self):
        self.cursor.close()
        self.mydb.close()
