from .DbManager import DbManager
import json
import mariadb


class BusinessDAO:
    def __init__(self):
        self.__con = DbManager().getConnection()
        self.__cur = self.__con.cursor()

    def getBusiness(self):
        self.__cur.callproc("getCustomerView")
        self.__all_cols = [desc[0] for desc in self.__cur.description]
        return  self.__cur.fetchall(), self.__all_cols

    def addBusiness(self, data, contact_id):
        try:
            self.__cur.callproc("addBusiness", (json.dumps(data), contact_id))
            self.__con.commit()

        except mariadb.Error as e:
            print(str(e))







