[rucksack-devel] delete-instances method

Henrik Hjelte henrik at evahjelte.com
Fri Feb 2 17:55:06 UTC 2007


May I propose adding an easier way to remove instances from the
database, something like the method below?

Cheers,
Henrik Hjelte


(in-package :rucksack)

(defmethod delete-instances ((rucksack standard-rucksack) instances)
  (let ((rucksack-roots (rucksack-roots rucksack)))
    (flet ((delete-instance (instance)
             (let ((class-index (rucksack-class-index rucksack
                                                      (class-of
instance)
                                                      :errorp nil))
                   (indexed-slot-names (rucksack-indexed-slots-for-class
                                        rucksack
                                        (class-of instance)))
                   (oid (object-id instance))
                   (class-name (class-name (class-of instance))))
               (when class-index
                 (index-delete class-index oid oid))
               (loop for slot-name in indexed-slot-names do
                     (index-delete (rucksack-slot-index rucksack
                                                        class-name
                                                        slot-name)
                                   (slot-value instance slot-name)
                                   oid
                                   :if-does-not-exist :ignore))
               (when (member oid rucksack-roots)
                 (delete-rucksack-root instance rucksack)))))
      (mapcar #'delete-instance instances))))





More information about the rucksack-devel mailing list