MCPcopy Index your code
hub / github.com/totaljs/framework / addRelation

Function addRelation

graphdb.js:365–494  ·  view source on GitHub ↗
(self, relation, indexA, indexB, callback)

Source from the content-addressed store, hash-verified

363}
364
365function addRelation(self, relation, indexA, indexB, callback) {
366
367 // Workflow:
368 // Has "A" relation nodes?
369 // Has "B" relation nodes?
370 // Create "A" relation with "B"
371 // Create "B" relation with "A"
372 // Register relation to global relations
373
374 var tasks = [];
375 var relA = null;
376 var relB = null;
377
378 var tmprelation = { index: relation.index, pageindex: 0, documentindex: 0, locked: false, private: true };
379
380 tasks.push(function(next) {
381 self.read(indexA, function(err, doc, relid) {
382 if (doc) {
383 relA = relid;
384 next();
385 } else {
386 tasks = null;
387 next = null;
388 callback(new Error('GraphDB: Node (A) "{0}" not exists.'.format(indexA)));
389 }
390 });
391 });
392
393 tasks.push(function(next) {
394 self.read(indexB, function(err, doc, relid) {
395 if (doc) {
396 relB = relid;
397 next();
398 } else {
399 tasks = null;
400 next = null;
401 callback(new Error('GraphDB: Node (B) "{0}" not exists.'.format(indexB)));
402 }
403 });
404 });
405
406 tasks.push(function(next) {
407
408 if (relA == 0) {
409 next();
410 return;
411 }
412
413 checkRelation(self, relation, relA, indexB, function(err, is) {
414 if (is) {
415 tasks = null;
416 next = null;
417 callback(new Error('GraphDB: Same relation already exists between nodes (A) "{0}" and (B) "{1}".'.format(indexA, indexB)));
418 } else
419 next();
420 });
421 });
422

Callers 1

insRelationFunction · 0.85

Calls 6

callbackFunction · 0.85
checkRelationFunction · 0.85
addRelationDocumentFunction · 0.85
pushRelationDocumentFunction · 0.85
updDocumentRelationFunction · 0.85
nextFunction · 0.70

Tested by

no test coverage detected