Skip to content

Commit e4d2e03

Browse files
author
chris
committed
Adding graph() method
1 parent 6af19c4 commit e4d2e03

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

lib/tripod.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,7 @@ var Tripod = function(dbName,collectionName) {
2323
Tripod.prototype.describe = function(r,c,callback) {
2424
c = (c==null) ? this._config.get("defaultContext") : c;
2525
// todo: alias c and r
26-
this._getCollection(function(err,collection) {
27-
collection.findOne({_id:{"r":r,"c":c}},function(err,doc) {
28-
if (err) {
29-
callback(err,null);
30-
} else {
31-
var graph = new TripleGraph();
32-
graph.addTripodDoc(doc);
33-
callback(null,graph);
34-
}
35-
})
36-
})
26+
this.graph({_id:{"r":r,"c":c}},callback);
3727
};
3828

3929
/**
@@ -42,20 +32,7 @@ Tripod.prototype.describe = function(r,c,callback) {
4232
* @param callback
4333
*/
4434
Tripod.prototype.multiDescribe = function(ids,callback) {
45-
var query = {_id: {'$in':ids}};
46-
this._getCollection(function(err,collection) {
47-
collection.find(query).toArray(function(err,docs) {
48-
if (err) {
49-
callback(err,null);
50-
} else {
51-
var graph = new TripleGraph();
52-
docs.forEach(function(doc) {
53-
graph.addTripodDoc(doc);
54-
});
55-
callback(null,graph);
56-
}
57-
})
58-
})
35+
this.graph({_id: {'$in':ids}},callback);
5936
};
6037

6138
/**
@@ -80,6 +57,27 @@ Tripod.prototype.getViewForResource = function (v,r,c,callback) {
8057
});
8158
};
8259

60+
/**
61+
* Fetch a graph based on a query
62+
* @param query
63+
* @param callback
64+
*/
65+
Tripod.prototype.graph = function(query,callback) {
66+
this._getCollection(function(err,collection) {
67+
collection.find(query).toArray(function(err,docs) {
68+
if (err) {
69+
callback(err,null);
70+
} else {
71+
var graph = new TripleGraph();
72+
docs.forEach(function(doc) {
73+
graph.addTripodDoc(doc);
74+
});
75+
callback(null,graph);
76+
}
77+
})
78+
})
79+
}
80+
8381
/**
8482
* Get a graph containing the views of type v for the resources represented in the Array ids
8583
* @param v - view type

0 commit comments

Comments
 (0)