This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
83 lines (71 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* global rdf:true */
'use strict';
function RdfstoreStore (store) {
var
self = this,
rdf = store.rdf;
self.graph = function (iri, callback) {
store.graph(iri, function (success, graph) {
if (success) {
callback(graph);
} else {
callback(null);
}
});
};
self.match = function (iri, subject, predicate, object, callback, limit) {
self.graph(iri, function (graph) {
if (!graph) {
callback(null);
} else {
callback(graph.match(subject, predicate, object, limit));
}
});
};
self.add = function (iri, graph, callback) {
store.clear(iri, function () {
store.insert(graph, iri, function (success) {
if (success) {
callback(graph);
} else {
callback(null, 'couldn\'n insert graph');
}
});
});
};
self.merge = function (iri, graph, callback) {
store.insert(graph, iri, function (success) {
if (success) {
callback(graph);
} else {
callback(null, 'couldn\'n insert graph');
}
});
};
self.remove = function (iri, graph, callback) {
self.graph(iri, function (oldGraph) {
var newGraph = rdf.Graph.difference(oldGraph, graph);
self.add(iri, newGraph, function (addedGraph) {
callback(!!addedGraph);
});
});
};
self.removeMatches = function (iri, subject, predicate, object, callback) {
self.graph(iri, function (oldGraph) {
var newGraph = oldGraph.removeMatches(subject, predicate, object);
self.add(iri, newGraph, function (addedGraph) {
callback(!!addedGraph);
});
});
};
self.delete = function (iri, callback) {
store.clear(iri, function (success) {
if (success) {
callback(true);
} else {
callback(null, 'couldn\'n delete graph');
}
});
};
};
module.exports = RdfstoreStore;