options to store data?

Discussion in 'Rebol' started by leke, Jul 18, 2010.

  1. leke

    leke New Member

    hi, I have an app which requires a lot of data access and modification. I'm going with the flat-file DB model, but was wondering which was the best way to structure my data. Maybe there is only one way (see below), or maybe you could suggest something better?
    Oh, and I have a problem with my code below. It looks like it stores correctly in the block 'db', but then writing to the file, I can't get it to keep its block structure -- which I need to start playing with it later on.

    Thanks :)
    rebol[ file: %make-club-data2.r ]
    club-id-record: 0
    add-club-id-record: func  ["Increment the ID."] [
    	club-id-record: club-id-record + 1
    teams: [ 
    "Manchester United"
    "etc..." ]
    club-data: [ 
    	none ]
    db-file: %clubs-db.txt
    db: []
    enter-db-new-club: func ["Writes club data to DB."] [
    	append db to-block mold/all reduce club-data
    loop length? teams [enter-db-new-club]
    write %clubs-db.txt to-block mold/all db
  2. Sunanda

    Sunanda New Member

    Change the write to:
    save %clubs-db.txt db
    and it should work.

    To reload the data:
     db: load %clubs-db.txt
  3. Graham

    Graham Developer Staff Member

    I think it's safer to save in a serialized format so use save/all instead of save.

    Also, I think it's safer to store your records in a block .. like this

    enter-db-new-club: func ["Writes club data to DB."] [
    	append/only db copy reduce club-data
  4. leke

    leke New Member

    Thanks for the tips :)
    Could you tell me the difference between SAVE and WRITE? Apart from the obvious refinements, I think they fundamentally do the same thing. But to me, SAVE just seemed to magically do what WRITE couldn't. How come it worked?

    >> ? save
         Saves a value or a block to a file or url.
    >> ? write
         Writes to a file, url, or port-spec (block or object).
  5. Graham

    Graham Developer Staff Member

    Save "saves values" .. not just text. So, it's a format that Rebol can reload.
  6. leke

    leke New Member

    Ahh, now I get it. Thanks :)

Share This Page