import psycopg2

# see this tutorial for getters and setters
# https://www.python-course.eu/python3_properties.php

class PgConnection:
    def __init__(self, ddbb):
        self.__cursor = None
        method=1
        if method== 1:
            HOST = "127.0.0.1"
            PORT = "5432"
            USER = "postgres"
            PASSWORD = "asimarro"
            DB = ddbb 

        elif method==2:
            HOST = ""#link
            PORT = "5432"
            USER = "docker"
            PASSWORD = "docker"
            DB = "gis2"  
        try:
            self.__connection = psycopg2.connect(user = USER,
                                  password = PASSWORD,
                                  host = HOST,
                                  port = PORT,
                                  database = DB
                                  )
            self.__cursor = self.__connection.cursor()
            print(DB, USER)
        except (Exception, psycopg2.Error) as error :
            print ("Error while connecting to PostgreSQL", error)
            

    @property
    def cursor(self):
        return self.__cursor

    @property
    def connection(self):
        return self.__connection

