Coder Social home page Coder Social logo

morgul / dustbin Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 0.0 284 KB

A slim wrapper around localStorage and sessionStorage that allows for NoSQL style access. It's basically a JSON-backed object database for your web browser.

License: MIT License

JavaScript 100.00%

dustbin's People

Contributors

lordnull avatar morgul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dustbin's Issues

Add RequireJS support

This module should (optionally) be able to be used with RequireJS.

It is incredibly important that RequireJS be optional. It should always be usable as a normal javascript include.

query and get do not return key of stored item

It can be useful to know what key an item was stored in to make later retrieval easier, as well as allow for reference by other objects. Perhaps stored as a '_key' property, or using an interal '_id' property.

It may be useful to store objects wrapped to allow meta data to avoid needing to dictate any form of structure upon the stored data.

[RFC] Add Link Support

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.

Implement Query API

Implement a query api, inspired by django's query api.

Basically, how I would like this to work is like this:

dustbin.query({someKey: "valueToMatch", someOtherKey: "someOtherValueToMatch"});

We can support the field api from django like this:

dustbin.query({someKey__lt: 5, someOtherKey__contains: "partial string"});

Alternatively, we could do this using a jugglingdb like api:

dustbin.query({lessThan: {someKey: 5}, contains: {someOtherKey: "partial string"}});

I'm not sure which I like better.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.