Created
June 4, 2011 10:13
-
-
Save michael/1007780 to your computer and use it in GitHub Desktop.
Data.js Query Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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