You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,4 +40,26 @@ services:
40
40
- database:database
41
41
```
42
42
43
-
Note: if you extend the `semtech/mu-export-js-template` with an `export.js` file instead of mounting a volume in `/config`, the `ONBUILD` commands of the `semtech/mu-javascript-template` will not be executed in your image since `ONBUILD` is only executed one level deep.
43
+
Note: if you extend the `semtech/mu-export-js-template` with an `export.js` file instead of mounting a volume in `/config`, the `ONBUILD` commands of the `semtech/mu-javascript-template` will not be executed in your image since `ONBUILD` is only executed one level deep.
44
+
45
+
## Using variables in the export query
46
+
You can also define variables in your SPARQL export query which will be replaced with query param values at runtime. Therefore, we use [ES6's tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals).
47
+
48
+
Import the `template` tag function from `/app/template.js` in your `export.js` and apply the tag function on your query. You can then define variables in your SPARQL query using `${'myVariable'}`. At runtime the variable will be replaced with the value provided in the `myVariable` query param of the request.
49
+
50
+
An example `export.js` file may look as follows:
51
+
52
+
```javascript
53
+
export default [
54
+
{
55
+
path: '/example',
56
+
format: 'text/csv',
57
+
query: `SELECT * FROM <http://mu.semte.ch/application> WHERE { ?s a ${'class'} } LIMIT 100`,
58
+
file: 'export-example.csv'
59
+
},
60
+
...
61
+
];
62
+
63
+
```
64
+
65
+
A GET request on `/example?class=<http://xmlns.com/foaf/0.1/Person>` will export the first 100 URIs of type `foaf:Person`.
0 commit comments