MarkLogic 8 - Node.js Client API - Can I do a SPARQL Query?

275 views Asked by At

As the title says, I want to know if I can do a SPARQL query in the node.js client API or if I need to use the Server Side Javascript API.

1

There are 1 answers

2
joemfb On BEST ANSWER

The MarkLogic node.js client API can evaluate SPARQL queries. See the jsdoc here: http://docs.marklogic.com/jsdoc/graphs.html#sparql

Update: here's a full example:

var marklogic = require('marklogic')
var config = { /* ... */ }
var db = marklogic.createDatabaseClient(config)

db.graphs.sparql(
  'application/sparql-results+json',
  'select ?s ?p ?o\n' +
  'where { ?s ?p ?o }\n' +
  'limit 10'
)
.result()
.then(function(response) {
  console.log(response.head)
  console.log(response.results)
})
.catch(console.log.bind(console))

Note that the results format (the first argument to db.graphs.sparql()) must be a known semantic format, as described here.