[rucksack-devel] SB-SYS:FD-STREAM for "file /tmp/rs-tute/objects" {B1CC241}> is closed

Helmut G. Enders helmut at cybernetic-systems.de
Fri Oct 3 10:40:38 UTC 2008


I try to store an instance with  a  persistent list of persistent objects as a slot-value.
E.g.  an invoice with a list of invoice items.

Do I have to save a list of unique-ids and then fetch all objects with these ids (sql like),
or is my attempt simply the wrong approach.

Helmut




(defpackage :rucksack-tutorial
  (:nicknames :rs-tute)
  (:use :cl :rucksack))
(in-package :rucksack-tutorial)
(defvar *rs-tute-directory* #p"/tmp/rs-tute/")

(with-rucksack (rs *rs-tute-directory* :if-exists :supersede)
   (with-transaction ()
     (defclass contact-details ()
        ((unique-id    :initarg :unique-id :accessor unique-id-of
		     :index :number-index
                      :unique t
		     :documentation "A unique number for each contact in our DB")
          (name       :initarg :name :accessor name-of
		     :index :case-insensitive-string-index
	             :documentation "The full name of the contact")

         (list-of-friends
                      :initarg :friends :accessor friends
		     :documentation "All the friends."))
       (:metaclass persistent-class)
       (:index t))
     ))


(defun make-my-friends ()
  (declare (optimize (debug 3)))
    (with-rucksack (rs *rs-tute-directory*)
     (with-transaction ()
       (loop with fs = nil
             for x from 1 upto 1000
             do  (setf fs (p-cons (make-instance 'contact-details
                                                  :unique-id x
                                                  :name (format nil "Friend~D" x)
                                                  :friends nil) fs))
             finally    (make-instance 'contact-details :name "Helmut" :friends fs)))))


(defun find-contact-by-name (name)
   (with-rucksack (rs *rs-tute-directory*)
     (with-transaction ()
       (rucksack-map-slot rs 'contact-details 'name
			 (lambda (contact)
			   (return-from find-contact-by-name contact))
			 :equal name)))
   nil)

(defun list-my-friends ()
  (declare (optimize (debug 3)))
  (with-rucksack (rs *rs-tute-directory*)
     (with-transaction ()
        (loop with me =  (find-contact-by-name "Helmut")
              for f in (unwrap-persistent-list (friends me))
              do (print (name-of f))))))

(defun test ()
   (make-my-friends)
   (list-my-friends))




More information about the rucksack-devel mailing list