What!? You just want us to just whip out an object database, eh? ;)

Ok, why not....  Here is a small "contacts" database keyed by email.
You can expand or reduce the record definition without corrupting
or affecting the database.

REBOL [Title: "Email Contact Database"]

db-file: %data.r
record: context [name: email: phone: web: none]
database: []

load-data: has [data] [
        data: load/all db-file
        clear database
        foreach item blk [
                item: make record item
                repend database [item/email item]
        ]
]

save-data: has [data] [
        data: copy []
        foreach [key obj] database [
                append/only data third obj
        ]
        save db-file data
]

find-data: func [email] [select database email]

remove-data: func [email] [remove/part find database email 2]

insert-data: func [email' name' phone' web'] [
        repend database [
                email'
                make record [
                        email: email'
                        name: name'
                        phone: phone'
                        web: web'
                ]
        ]
]

You can expand/contract the record definition at any time.

This is untested... but should be close to working, less a few
minor typos.  If you expect to grow this database to a large
size, you will want to MAKE HASH! the database when you load
it.

-Carl

PS: The remove/part on find really does work. Remove none is
allowed in Core 2.5.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Dr. Louis A. Turk
Sent: Monday, April 09, 2001 4:35 AM
To: [EMAIL PROTECTED]
Subject: [REBOL] Object Database


I am trying to learn how to make an object database using REBOL.  I need a
simple, but complete, working example.  Can anyone supply one?

Also, what are probably dumb questions:

1. If an object database contains data, will that data be lost if another
field is added?

2. Is there any way to change the name of an object in a database without
losing the data in the object?

3. Would it be possible to use email addresses for the names of the objects?

Thanks in advance for any help.

Louis


--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to