ff-notes / ron

Haskell implementation of RON and RON-RDT
BSD 3-Clause "New" or "Revised" License
65 stars 9 forks source link

[DRAFT] Remove nested objects from documents, leave only one object per document #129

Open cblp opened 4 years ago

cblp commented 4 years ago

Current state

Now you can describe a number of nested objects, for example

(struct_set Note
  text RgaString
  tags (RGA (ObjectRef Tag))
  value Integer)

means that Note object chunk and chunks for all objects representing its fields (RGA for text and RGA for tags) will be stored inside the document frame.

All referenced objects (Tag in this example) will not be stored in this document, and the user has to put the explicitly into other documents.

This will generate a type like this:

data Note = Note
  { text :: RgaString, -- ~ [Char]
    tags :: RGA (ObjectRef Tag), -- ~ [UUID]
    value :: Integer
  }

RGA a is meant just to represent a value, so it is just a wrapper around [a].

A user can get the whole document state with the readObject function, with all internal objects decoded but without external object-refs resolved.

To resolve referenced objects, the user must take ObjectRefs and call loadDocument (involving IO) and readObject (in "pure" State) for them.

Problem

This seems unclear and complicated.

Proposal

  1. Put each object in its own document.
  2. Remove explicit ObjectRef from Schema, always considering a nested object a reference. Generated code will always contain references for objects.

Example

(struct_set Note
  text RgaString
  tags (RGA Tag)
  value Integer)
data Note = Note
  { text :: ObjectRef RgaString, -- ~ UUID
    tags :: ObjectRef RGA Tag, -- ~ UUID
    value :: Integer
  }

Open questions

  1. Does readObject load data from backend each time?
  2. What about transactions if there are no documents?
cblp commented 4 years ago

What about transactions if there are no documents?