jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.33k stars 5.53k forks source link

Suggestion: Data.js as an extension to Underscore #207

Closed michael closed 13 years ago

michael commented 13 years ago

Just wanted to propose Data.js as an extension to Underscore (in case you see it fit for being mentioned in the docs).

http://substance.io/#michael/data-js http://github.com/michael/data

dvv commented 13 years ago

@michael: you might want to check [dvv/underscore-data] for adding support of mongodb-styled queries and translation of vanilla URL querystrings to structured queries (RQL === Resource Query Language)

michael commented 13 years ago

@dvv: Neat! Data.js Queries are inspired by Freebase's MQL. The features are limited yet. For the moment I solve complex querying tasks by specifying multiple queries. Those are executed independently on the server, the results are combined and sent back as a subgraph, containing matched nodes.

Fetching a project along with the associated tasks would look like so:

graph.fetch([
  {type: "/type/project", _id: projectId},
  {type: "/type/task", project: projectId}
], function(err, nodes) {} );

However improving query capabilities is something I'm really interested in. I'll definitely consider your approaches! You're welcome to contribute if you're interested. Also I think adding MongoDB as a backend would be reasonable, as their dynamic query interface should be easy to delegate to. Nevertheless for now I'll concentrate on CouchDB support, as for my projects it's a better fit, though I'd appreciate if someone's up to contributing a MongoAdapter. :)

michael commented 13 years ago

I don't think that RQL would be useful though, as with Data.js HTTP is completely hidden from the interface. You can easily switch to web-sockets as the transport mode, while the interface stays the same. Thus, I guess I'll stick with JSON-based query objects and take some inspiration from Mongo.

dvv commented 13 years ago

Very well. I never meant RQL is for HTTP, no. Just a convenient way to serialize nested queries to a form which is native to web developers: e.g. (a=b|c!=d)&e<f. In gets parsed to JS object (I guess you mean those saying "JSON-based query objects") which then can be mapped to any form of query terms. E.g. to mongo search directives. Which in turn is well-designed and quite common to be reused in another, non-mongodb, data stores.

jashkenas commented 13 years ago

Sure thing -- added a link. That's some truly fantastic documentation on Substance.

michael commented 13 years ago

Highly inspired by your documentation work, though. :) Thanks for being added.

@dvv Thanks, will consider this. I prefer using JS objects because they can be easily manipulated programmatically. I'd then see RQL support implemented as a higher level DSL that maps to a corresponding JS query object.