leah blogs

January 2005

29jan2005 · FramerD

I’ve been playing with FramerD recently, and I think I’m gonna write a Ruby interface to it.

FramerD is an Object-Oriented Database which was orignally made for AI, but I think you can use it for storing just about everything.

The actual fun is the language you use to talk to FramerD: a dialect of Scheme. As a sample, I’ve imported my local ruby-talk archive into it. This piece of code does that:

(define ruby-talk (sorted (getfiles "/home/chris/Mail/ruby-talk")))

(define mail-pool  (use-pool "mail.pool"))
(define mail-index (use-index "mail.index"))

(doseq (mail ruby-talk)
  (lineout mail)
  (define error
    (signals-error? (let ((frame (read-mime (filestring mail))))
                      (fadd! frame 'obj-name (fget frame 'SUBJECT))
                      (let ((ref (fget frame 'REFERENCES)))
                        (if ref
                            (fset! frame 'REFERENCES
                                   (reverse (tx-segment ref
                                       '(+ {" " "\n"}))))))
                      (frame-create mail-pool frame)
                      (index-frame mail-index frame 'FROM)
                      (index-frame mail-index frame 'MESSAGE-ID)
                      (index-frame mail-index frame 'REFERENCES))))
  (if error
      (lineout "error on " mail ": " error)))

(commit-pool mail-pool)
(commit-index mail-index)

Now, I can easily query the datastore. For example, get all mail by me:

(find-frames mail-index
             'FROM "Christian Neukirchen <chneukirchen@gmail.com>")

Or, get all my Subject:s:

(get (find-frames "mail.index"
                  'FROM "Christian Neukirchen <chneukirchen@gmail.com>")
     'SUBJECT)
{;; There are 14 results
 "Re: Collecting list of most wanted libraries and apps to port to\n ruby"
 "Merry Christmas"
 "[ANN] Nukumi2 0.1"
 ...}

It’s a wonderful thing and would make a great backend for a Ruby OODB, I think.

NP: Bob Dylan—Stuck Inside Of Mobile With The Memphis Blues Again

Copyright © 2004–2022