from connect import connect

conn = connect()
class MyQueryClass:
    def query_select(self, query, args=(), one=False):
        try:
            with conn.cursor() as cursor:
                cursor.execute(query, args)
                r = [dict((cursor.description[i][0], value) \
                        for i, value in enumerate(row)) for row in cursor.fetchall()]
                return (r[0] if r else None) if one else r
        except:
            return False

    def query_insert(self, query, args=()):
        try:
            with conn.cursor() as cursor:
                cursor.execute(query, args)
                conn.commit()
                return cursor.fetchone()[0]
        except: 
            return False

    def query_delete(self, query, args=()):
        try:
            with conn.cursor() as cursor:
                cursor.execute(query, args)
                if(cursor.rowcount != 0):
                    conn.commit()
                    return True
            return False
        except: 
            return False

    def query_update(self, query, args=()):
        try:
            with conn.cursor() as cursor:
                cursor.execute(query, args)
                if(cursor.rowcount != 0):
                    conn.commit()
                    return True
            return False
        except: 
            return False

    def query_proverka(self, query, args=()):
        try:
            with conn.cursor() as cursor:
                cursor.execute(query, args)
                if(cursor.rowcount > 0):
                    return True
            return False
        except: 
            return False