Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add Link Support #5

Open
Morgul opened this issue Apr 16, 2013 · 0 comments
Open

[RFC] Add Link Support #5

Morgul opened this issue Apr 16, 2013 · 0 comments

Comments

@Morgul
Copy link
Owner

Morgul commented Apr 16, 2013

I'm proposing we add support for links between objects in Dustbin. This could be very useful to managing data relationships.

Link Format:

A link would be an object of this structure:

{
    tag: [{bucket: "some_bucket", key: "some_key"}];
}

We would add links to the $metadata (proposed in #4 ), which would simply be the above object with multiple tags.

Working with Links

The first thing we would need is an api for adding/removing links:

// Add a link to obj1 from obj1 to obj2 with the tag 'tag'.
dustbin.link(obj1, 'tag', obj2);

// Add a link to obj1 from obj1 to the object at bucket/key with the tag 'tag'.
dustbin.link(obj1, 'tag', 'bucket', 'key');

// Adds links to obj1 from ob1 to obj2, obj3 and obj4 with the tag 'tag'.
dustbin.addLinks(obj1, 'tag', obj2, obj3, obj4);

// Adds links to obj1 from ob1 to the objects at 'bucket/ket1' and 'bucket/key2' with the tag 'tag'.
dustbin.addLinks(obj1, 'tag', ["bucket", "key1"], ["bucket", "key2"]);

// Remove a link from obj1 with the tag 'tag', that points to obj2.
dustbin.unlink(obj1, 'tag', obj2);

// Remove a link from obj1 with the tag 'tag', that points to the object 'bucket/key'.
dustbin.unlink(obj1, 'tag', 'bucket', 'key');

// Sets the links on object obj1 to the `link` object passed in.
dustbin.setLinks(obj1, {tag: [{bucket: "bucket", key: "someKey"}]});

These should cover most of the use cases. We still need the ability to work with the links:

// Get all links associated with the given tag. Returns a list of resolved objects.
dustbin.getLinks(obj1, 'tag');

// Link walk object 1
dustbin.walk(obj1, ["bucket", "tag"], [undefined, "someTag", true]);

// Link walk object 1, verbose syntax
dustbin.walk(obj1, {bucket: "bucket", tag: "tag"}, {tag: "someTag", keep: true});

This is pretty much the exact same link walking as Riak, with the exception that instead of using "_", I'm using undefined to mean "any". I believe that simply not specifying one of the options is more straightforward than an arbitrary (if commonly used) string convention.


In the end, the API is less important than answering the question, "Will this be useful?". While I can see use cases, I'm not certain that they're worth adding this support in.

If we're not sure if we want this, but thing it might be useful in some places, I'd like to write it as an extension to Dustbin; i.e. if you include dustbin.js and dustbin-links.js the DustBin object would have it's prototype extended to support links. This way, only the people who want them will need to include the additional code, and any overhead it might induce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant