def get_next_connection_index(db, profile_id, folder_path):
    """Finds next connection index

    Args:
        db (object): The db object
        profile_id (int): The id of the profile
        folder_path (str): The folder path used for grouping and nesting connections

    Returns:
        Next connection index value
    """
    res = db.execute('''SELECT max(`index`)
                        FROM profile_has_db_connection
                        WHERE profile_id=? and folder_path=?''',
                    (profile_id, folder_path)).fetch_one()

    return res[0] + 1 if res[0] is not None else 1