couchdb-compile icon indicating copy to clipboard operation
couchdb-compile copied to clipboard

Support a "merge-into-parent" mechanism?

Open natevw opened this issue 5 years ago • 2 comments

Hello again! I wanted to touch base regarding a feature idea I had for my similar project: https://github.com/natevw/putdoc/issues/9

To summarize my notes there, I'm wondering if you would also like to support a feature that will merge fields from certain JSON file(s) into their parent object? So that way one can set multiple fields in a top-level document using one JSON file [or possibly multiple, see below].

How it might look:

merge_example/
    _id			('example')
    _data.json		('{"type":"container", "name": "My Container", "owner":"me"}')
    _attachments
        file1.jpg
        file2.pdf
        [etc…]

Creates a document:

`{
  "_id":"example",
  "type":"container",
  "name": "My Container",
  "owner":"me",
  "_attachments": {/* … */}
}

It should be a relatively easy add into putdoc at least technically, but if you had interest too I wanted to collaborate on some of the design decisions:

  1. ~~How to trigger it? My basic idea so far is by a special file name (like we have with _attachments and _docs folders) in the example above it's _merge or maybe e.g. _fields/_data/…. The actual file 99% of the time would have a JSON extension but I suppose could theoretically be a nested document [not sure the use case but keep things consistent…] or possibly some other extension that is used for serializing an object (think YAML/XML but to be clear I have no plans to support those in putdoc).~~ I implemented this via the _data option, for better or worse.
  2. ~~Is it simple and worthwhile enough to support multiple such files e.g. _merge.one.json _merge.two.json and _merge.json would all three have their fields merged into their context.~~ I also implemented this. I left the merge order unspecified; for now conflicting (i.e. duplicate) keys are discouraged and should not be expected to yield stable results.
  3. Any other feedback?

Thanks for your time!

natevw avatar Feb 22 '19 18:02 natevw

Also pinging @benoitc @iblis17 as relatively recent contributors to couchapp/erica. I don't want to file so many issues in those projects yet, but would appreciate any input you have in the meantime.

natevw avatar Feb 22 '19 18:02 natevw

This is now implemented in [email protected].

If there's interest, it would be good to get this supported across other utilities as a standard feature! For now I included a compatibility warning in my documentation for it.

natevw avatar Mar 21 '19 23:03 natevw