Skip to content

Commit ac7efea

Browse files
committed
Add support for SPARQL
There's support for sending SPARQL queries and importing various sets of the library at this time. Mostly query and update should be of interest.
1 parent e0dce8a commit ac7efea

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ COPY . /usr/src/app
1111
RUN ln -s /app/app.js /usr/src/app/
1212
RUN npm install
1313

14+
ENV MU_SPARQL_ENDPOINT 'http://database:8890/sparql'
15+
ENV MU_APPLICATION_GRAPH 'http://mu.semte.ch/application'
16+
1417
CMD sh boot.sh
1518

1619
ONBUILD ADD . /app/

helpers/mu/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import app from './server';
2+
import sparql from './sparql';
23

34
const mu = {
4-
app: app
5+
app: app,
6+
sparql: sparql,
7+
SPARQL: sparql.sparql,
8+
query: sparql.query,
9+
update: sparql.update,
510
}
611

7-
export { app };
12+
const SPARQL = mu.SPARQL, query = mu.query, update = mu.update;
13+
14+
export { app , sparql, SPARQL, query, update };
815
export default mu;

helpers/mu/sparql.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import SC2 from 'sparql-client-2';
2+
const { SparqlClient, SPARQL } = SC2;
3+
4+
//==-- logic --==//
5+
6+
// builds a new sparqlClient
7+
function newSparqlClient() {
8+
return new SparqlClient( process.env.MU_SPARQL_ENDPOINT ).register({
9+
mu: 'http://mu.semte.ch/vocabularies/',
10+
muCore: 'http://mu.semte.ch/vocabularies/core/',
11+
muExt: 'http://mu.semte.ch/vocabularies/ext/'
12+
});
13+
}
14+
15+
// executes a query (you can use the template syntax)
16+
function query( queryString ){
17+
return newSparqlClient().query( queryString ).execute();
18+
};
19+
20+
// executes an update query
21+
const update = query;
22+
23+
24+
//==-- exports --==//
25+
const exports = {
26+
newSparqlClient: newSparqlClient,
27+
SPARQL: SPARQL,
28+
sparql: SPARQL,
29+
query: query,
30+
update: update
31+
}
32+
export default exports;
33+
34+
export { query, update, SPARQL as SPARQL, SPARQL as sparql, newSparqlClient };
35+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"babel-preset-es2015": "^6.18.0",
2222
"babel-preset-es2016": "^6.16.0",
2323
"babel-preset-es2017": "^6.16.0",
24-
"supervisor": "^0.12.0"
24+
"supervisor": "^0.12.0",
25+
"sparql-client-2": "^0.6.0"
2526
},
2627
"author": "Aad Versteden <[email protected]>",
2728
"license": "MIT",

0 commit comments

Comments
 (0)