def convert()

in modular_sdk/models/pynamodb_extension/pynamodb_to_pymongo_adapter.py [0:0]


    def convert(cls, action: Action):
        if isinstance(action, SetAction):
            path, value = action.values
            if isinstance(value, Value):
                return {
                    '$set': {cls.path_to_raw(path): cls.value_to_raw(value)}
                }
            if isinstance(value,
                          _ListAppend):  # appending from one list to another is not supported. However, Dynamo seems to support it
                if isinstance(value.values[0], Path):  # append
                    return {
                        '$push': {cls.path_to_raw(path): {
                            '$each': cls.value_to_raw(value.values[1])}
                        }
                    }
                else:  # prepend
                    return {
                        '$push': {
                            cls.path_to_raw(path): {
                                '$each': cls.value_to_raw(value.values[0]),
                                '$position': 0
                            },
                        }
                    }
            # does not work, but the idea is right.
            # Only need to make right mongo query
            # if isinstance(value, _Increment):
            #     return {
            #         '$set': {cls.path_to_raw(path): {
            #             '$add': [f'${cls.path_to_raw(value.values[0])}', int(cls.value_to_raw(value.values[1]))]  # make sure it's int, it is your responsibility
            #         }}
            #     }
            # if isinstance(value, _Decrement):
            #     return {
            #         '$set': {cls.path_to_raw(path): {
            #             '$add': [f'${cls.path_to_raw(value.values[0])}', -int(cls.value_to_raw(value.values[1]))]  # make sure it's int, it is your responsibility
            #         }}
            #     }
            raise NotImplementedError(
                f'Operand of type: {value.__class__.__name__} not supported'
            )
        if isinstance(action, RemoveAction):
            path, = action.values
            return {
                '$unset': {cls.path_to_raw(path): ""}
                # empty string does not matter https://www.mongodb.com/docs/manual/reference/operator/update/unset/#mongodb-update-up.-unset
            }
        raise NotImplementedError(
            f'Action {action.__class__.__name__} is not implemented'
        )