Advertisement
Guest User

Untitled

a guest
Jun 25th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. this.has = function(conn, coll, label, value, type, callback) {
  2. if (label === undefined || value === undefined || type == undefined)
  3. return callback('Some arguments are missing!');
  4. if (typeof label !== 'string' || typeof type !== 'string')
  5. return callback('ARG1 and ARG3 must be strings!');
  6. type = type.toLowerCase();
  7. if (type !== 'vertex' && type !== 'edge' &&  type !== 'all')
  8. return callback("ARG3 must take as value 'vertex', 'edge' or 'all'!");
  9. var query = gremlin();
  10. async.auto({
  11. V: function(cb) {
  12. if (type === 'all' || type === 'vertex') {
  13. if (typeof value == 'string')
  14. query("g.V.has(%s, %s)", label, value);
  15. else
  16. query("g.V.has(%s, %d)", label, value);
  17. client.execute(query, function(err, response) {
  18. return cb(err, response.results);
  19. });
  20. } else
  21. cb(null);
  22. },
  23. E: function(cb) {
  24. if (type === 'all' || type === 'edge') {
  25. if (typeof value == 'string')
  26. query("g.E.has(%s, %s)", label, value);
  27. else
  28. query("g.E.has(%s, %d)", label, value);
  29. client.execute(query, function(err, response) {
  30. return cb(err, response.results);
  31. });
  32. } else
  33. cb(null);
  34. },
  35. has: ['V', 'E', function(cb, results) {
  36. if (results.V && !results.E)
  37. cb(null, results.V);
  38. if (results.E && !results.V)
  39. cb(null, results.E);
  40. if (results.V && results.E) {
  41. results.V.merge(results.E)
  42. cb(null, results.V);
  43. }
  44. }]
  45. }, function(err, res) {
  46. callback(err, res.has);
  47. });
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement