Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.has = function(conn, coll, label, value, type, callback) {
- if (label === undefined || value === undefined || type == undefined)
- return callback('Some arguments are missing!');
- if (typeof label !== 'string' || typeof type !== 'string')
- return callback('ARG1 and ARG3 must be strings!');
- type = type.toLowerCase();
- if (type !== 'vertex' && type !== 'edge' && type !== 'all')
- return callback("ARG3 must take as value 'vertex', 'edge' or 'all'!");
- var query = gremlin();
- async.auto({
- V: function(cb) {
- if (type === 'all' || type === 'vertex') {
- if (typeof value == 'string')
- query("g.V.has(%s, %s)", label, value);
- else
- query("g.V.has(%s, %d)", label, value);
- client.execute(query, function(err, response) {
- return cb(err, response.results);
- });
- } else
- cb(null);
- },
- E: function(cb) {
- if (type === 'all' || type === 'edge') {
- if (typeof value == 'string')
- query("g.E.has(%s, %s)", label, value);
- else
- query("g.E.has(%s, %d)", label, value);
- client.execute(query, function(err, response) {
- return cb(err, response.results);
- });
- } else
- cb(null);
- },
- has: ['V', 'E', function(cb, results) {
- if (results.V && !results.E)
- cb(null, results.V);
- if (results.E && !results.V)
- cb(null, results.E);
- if (results.V && results.E) {
- results.V.merge(results.E)
- cb(null, results.V);
- }
- }]
- }, function(err, res) {
- callback(err, res.has);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement