Skip to content

Instantly share code, notes, and snippets.

@michael
Created June 4, 2011 10:13
Show Gist options
  • Save michael/1007780 to your computer and use it in GitHub Desktop.
Save michael/1007780 to your computer and use it in GitHub Desktop.
Data.js Query Interface
// For a specific user get all document subscriptions, along with their corresponding
// documents, complete with creator, subjects, entites, and all content nodes (=children recursively)
query = {
"type": "/type/subscription",
"user": "/user/"+username,
"document": {
"creator": {},
"children": {_recursive: true},
"subjects": {},
"entities": {}
},
"creator": {}
}
// Usage:
graph.fetch(qry, function(err, nodes) {
console.log(nodes.keys());
});
// We should support basic range queries to make use of CouchDB views.
// Currently those range queries only work locally.
qry = {
"type": "/type/person",
"age>": 20
}
// How can we express "within" (would internally use startkey/endkey)
// All persons whose name is between "M" and "U".
qry = {
"type": "/type/person",
"name>=": "M",
"name<=": "U"
}
// All persons whose name is between "M" and "U".
qry = {
"type": "/type/person",
"name.between": ["M", "U"]
}
// Sometimes you might want do do fast queries using an index, but you want to apply further
// filters that can't be handled by the indexed query. You should be able to pass an additional
// query object that further narrows down the result. This is all done on the server, so the
// client can relax and network traffic gets minimized.
// Fetch all persons originating in Springfield containing "Simpsons" in their name
// with age >= 10
qry = {
"type": "/type/person",
"origin": "/location/springfield",
"_match": {
"name~": "Simpsons",
"age>=": 10
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment