<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply_to(self, db: Union[BaseDB, ABC_Mutable_Mapping], apply_deletes: bool = True) -> None: """ Apply the changes in this diff to the given database. You may choose to opt out of deleting any underlying keys. :param apply_deletes: whether the pending deletes should be applied to the database """

        for key, value in self._changes.items():
            if value is DELETED:
                if apply_deletes:
                    try:
                        del db[key]
                    except KeyError:
                        pass
                else:
                    pass
            else:
                db[key] = value