Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Object Database

From: carl:rebol at: 9-Apr-2001 8:28

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.