rdf-sparql-builder

0.2.2 • Public • Published

rdf-sparql-builder

build status npm version

rdf-sparql-builder helps building SPARQL queries in JavaScript code. Instead of error-prone string concatenations, method chaining allows writing queries without switching the programming language. The RDF/JS data model is used for terms like named nodes and variables.

Usage

The package exports an object with all the required functions. It can be imported in your code like this:

import * as sparql from 'rdf-sparql-builder'

Example

The following example shows how to build a simple query. The examples folder contains more examples showing all kinds of features supported by the package.

import rdf from '@rdfjs/data-model'
import namespace from '@rdfjs/namespace'
import * as sparql from 'rdf-sparql-builder'

const ns = {
  ex: namespace('http://example.org/'),
  rdf: namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
}

const observation = rdf.variable('observation')
const date = rdf.variable('date')
const temperature = rdf.variable('temperature')

const query = sparql.select([date, temperature])
  .where([
    [observation, ns.rdf.type, ns.ex.Observation],
    [observation, ns.ex.date, date],
    [observation, ns.ex.temperature, temperature]
  ])

console.log(query.toString())

Readme

Keywords

none

Package Sidebar

Install

npm i rdf-sparql-builder

Weekly Downloads

181

Version

0.2.2

License

MIT

Unpacked Size

63 kB

Total Files

63

Last publish

Collaborators

  • bergos