Package detail

@comunica/query-sparql-rdfjs

comunica3.4kMIT4.5.0

A SPARQL query engine for querying over RDF/JS sources

comunica, sparql, engine, query

readme

Comunica SPARQL RDF/JS

npm version

Comunica SPARQL is a SPARQL query engine for JavaScript for querying RDF/JS sources that implement the Source interface.

This module is part of the Comunica framework.

Install

$ yarn add @comunica/query-sparql-rdfjs

Query

const QueryEngine = require('@comunica/query-sparql-rdfjs').QueryEngine;
const N3Store = require('n3').Store;
const DataFactory = require('n3').DataFactory;

// This can be any RDFJS source
const store = new N3Store();
store.addQuad(DataFactory.quad(
  DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Belgium')));
store.addQuad(DataFactory.quad(
  DataFactory.namedNode('a'), DataFactory.namedNode('b'), DataFactory.namedNode('http://dbpedia.org/resource/Ghent')));

// Create our engine, and query it.
// If you intend to query multiple times, be sure to cache your engine for optimal performance.
const myEngine = new QueryEngine();
const bindingsStream = await myEngine.queryBindings(`
  SELECT ?s ?p ?o WHERE {
    ?s ?p <http://dbpedia.org/resource/Belgium>.
    ?s ?p ?o
  } LIMIT 100`, {
  sources: [store],
});

// Consume results as a stream (best performance)
bindingsStream.on('data', (binding) => {
  console.log(binding.toString()); // Quick way to print bindings for testing

  console.log(binding.has('s')); // Will be true

  // Obtaining values
  console.log(binding.get('s').value);
  console.log(binding.get('s').termType);
  console.log(binding.get('p').value);
  console.log(binding.get('o').value);
});
bindingsStream.on('end', () => {
  // The data-listener will not be called anymore once we get here.
});
bindingsStream.on('error', (error) => {
  console.error(error);
});

// Consume results as async iterable (easier)
for await (const binding of bindingsStream) {
  console.log(binding.toString());
}

// Consume results as an array (easier)
const bindings = await bindingsStream.toArray();
console.log(bindings[0].get('s').value);
console.log(bindings[0].get('s').termType);

_Read more about querying in an application._

Update

const QueryEngine = require('@comunica/query-sparql-rdfjs').QueryEngine;
const N3Store = require('n3').Store;

// This can be any RDFJS store
const store = new N3Store();

// Create our engine, and query it.
const myEngine = new QueryEngine();
const query = `
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
  <http://example/book1> dc:title "A new book" ;
                         dc:creator "A.N.Other" .
}
`;

// Execute the update
await myEngine.queryVoid(query, {
  sources: [store],
});

// Prints '2' => the store is updated
console.log(store.size);

_Read more about updating in an application._

Optimization

The RDFJS Source interface by default only exposed the match method. In order to allow Comunica to produce more efficient query plans, you can optionally expose a countQuads method that has the same signature as match, but returns a number or Promise<number> that represents (an estimate of) the number of quads that would match the given quad pattern. Certain Source implementations may be able to provide an efficient implementation of this method, which would lead to better query performance.

If Comunica does not detect a countQuads method, it will fallback to a sub-optimal counting mechanism where match will be called again to manually count the number of matches.

changelog

Changelog

All notable changes to this project will be documented in this file.

v4.5.0 - 2025-11-18

Added

Fixed

v4.4.1 - 2025-09-25

Fixed

v4.4.0 - 2025-09-17

Added

Changed

Fixed

v4.3.0 - 2025-06-17

Added

Changed

Fixed

v4.2.0 - 2025-04-29

Added

Changed

Fixed

v4.1.0 - 2025-02-11

v4.1.0 - 2025-02-11

Added

Changed

Fixed

v4.0.2 - 2024-10-16

Changed

Fixed

v4.0.1 - 2024-10-15

BREAKING CHANGES

The following breaking changes will only impact users of Node.js < 18 and users that develop custom components or engines with Comunica.

Added

Changed

Fixed

v3.3.0 - 2024-10-08

Added

Changed

Fixed

v3.2.3 - 2024-08-22

Fixed

v3.2.2 - 2024-08-19

Changed

Fixed

v3.2.1 - 2024-08-07

Added

Changed

Fixed

v3.2.0 - 2024-07-05

Added

Changed

Fixed

v3.1.2 - 2024-05-30

Fixed

Changed

v3.1.1 - 2024-05-11

Fixed

v3.1.0 - 2024-05-11

Added

Changed

Fixed

v3.0.3 - 2024-04-12

Changed

Fixed

v3.0.2 - 2024-04-10

Fixed

v3.0.1 - 2024-03-19

BREAKING CHANGES

Added

Fixed

Changed

v2.10.2 - 2024-01-09

Fixed

v2.10.1 - 2023-11-29

Fixed

v2.10.0 - 2023-10-27

Added

Changed

Fixed

v2.9.0 - 2023-09-07

Changed

Fixed

v2.8.3 - 2023-08-21

Changed

Fixed

v2.8.2 - 2023-08-10

Fixed

v2.8.1 - 2023-07-14

Fixed

v2.8.0 - 2023-07-04

Added

Changed

v2.7.1 - 2023-05-31

Changed

Fixed

v2.7.0 - 2023-05-24

Added

Changed

Fixed

v2.6.10 - 2023-03-10

Fixed

v2.6.9 - 2023-03-08

Changed

Fixed

v2.6.8 - 2023-03-06

Changed

Fixed

v2.6.7 - 2023-02-15

Added

v2.6.6 - 2023-02-08

Fixed

Changed

v2.6.5 - 2023-02-07

Fixed

v2.6.4 - 2023-02-02

Fixed

v2.6.3 - 2023-02-01

Fixed

v2.6.2 - 2023-01-31

Fixed

v2.6.1 - 2023-01-30

Fixed

v2.6.0 - 2023-01-26

Added

Changed

Fixed

v2.5.2 - 2022-11-18

Fixed

v2.5.1 - 2022-11-16

Fixed

v2.5.0 - 2022-11-09

Added

Changed

Fixed

v2.4.3 - 2022-09-06

Fixed

v2.4.2 - 2022-08-26

Fixed

v2.4.1 - 2022-08-24

Fixed

v2.4.0 - 2022-08-24

Added

Changed

Fixed

v2.3.0 - 2022-06-29

Added

Changed

Fixed

v2.2.1 - 2022-04-13

Fixed

v2.2.0 - 2022-04-12

Added

Changed

Fixed

v2.1.0 - 2022-03-09

Added

v2.0.6 - 2022-03-07

Fixed

v2.0.5 - 2022-03-04

Fixed

v2.0.4 - 2022-03-04

Fixed

v2.0.3 - 2022-03-02

Fixed

v2.0.2 - 2022-03-02

Fixed

v2.0.1 - 2022-03-02

BREAKING CHANGES

Added

Changed

v1.22.3 - 2021-10-19

Fixed

v1.22.2 - 2021-09-30

Changed

Fixed

v1.22.1 - 2021-09-22

Fixed

v1.22.0 - 2021-08-30

Added

Changed

Fixed

v1.21.3 - 2021-06-18

Fixed

v1.21.2 - 2021-06-14

Changed

v1.21.1 - 2021-04-27

Republish due to npm publishing failure of 1.21.0.

v1.21.0 - 2021-04-27

Added

Changed

Fixed

v1.20.0 - 2021-03-30

Added

Changed

Fixed

v1.19.2 - 2021-02-02

Changed

Fixed

v1.19.1 - 2021-01-22

Fixed

v1.19.0 - 2021-01-15

Changed

v1.18.1 - 2020-12-01

Fixed

v1.18.0 - 2020-11-02

Fixed

Added

Changed

v1.17.0 - 2020-09-25

Added

Changed

Fixed

v1.16.2 - 2020-08-24

Fixed

v1.16.1 - 2020-08-24

Fixed

v1.16.0 - 2020-08-24

Added

Fixed

Changed

v1.15.0 - 2020-08-13

Added

Changed

Fixed

v1.14.0 - 2020-07-24

Added

Changed

Fixed

v1.13.1 - 2020-06-11

Fixed

v1.13.0 - 2020-06-03

Fixed

Changed

v1.12.1 - 2020-04-27

Fixed

v1.12.0 - 2020-04-03

Changed

Added

Fixed

v1.11.1 - 2020-04-02

Added

Fixed

Changed

v1.11.0 - 2020-03-30

Added

Changed

Fixed

v1.10.0 - 2019-12-12

Added

Changed

Fixed

v1.9.4 - 2019-10-21

Changed

v1.9.3 - 2019-10-16

Added

Changed

Fixed

v1.9.2 - 2019-09-27

Added

Changed

Fixed

v1.9.1 - 2019-07-30

Fixed

v1.9.0 - 2019-07-29

Added

Fixed

Changed

v1.8.0 - 2019-06-13

Changed

v1.7.4 - 2019-05-29

Fixed

v1.7.3 - 2019-05-09

Fixed

v1.7.2 - 2019-05-03

Fixed

v1.7.1 - 2019-05-03

Fixed

Changed

v1.7.0 - 2019-04-11

Added

Fixed

v1.6.6 - 2019-04-03

Changed

Fixed

v1.6.5 - 2019-03-15

Added

Fixed

v1.6.4 - 2019-03-05

Fixed

v1.6.3 - 2019-02-27

Changed

v1.6.2 - 2019-02-26

Added

Changed

v1.6.1 - 2019-02-25

Fixed

v1.6.0 - 2019-02-22

Added

Changed

Fixed

v1.5.4 - 2019-01-31

Fixed

Changed

v1.5.3 - 2019-01-24

Fixed

v1.5.2 - 2019-01-17

Fixed

v1.5.1 - 2019-01-17

Fixed

v1.5.0 - 2019-01-02

Added

v1.4.6 - 2018-12-11

Fixed

v1.4.5 - 2018-12-11

Fixed

Changed

v1.4.4 - 2018-11-13

Fixed

v1.4.3 - 2018-11-09

Changed

v1.4.2 - 2018-11-05

Fixed

v1.4.1 - 2018-10-04

Fixed

v1.4.0 - 2018-10-03

Added

Fixed

1.3.0 - 2018-09-10

Added

1.2.2 - 2018-09-05

Fixes

1.2.1 - 2018-09-05

Fixes

1.2.0 - 2018-09-05

Added

Fixes

1.1.2 - 2018-06-26

Added

Fixes

1.1.1 - 2018-06-01

Fixes

1.1.0 - 2018-06-01

Added

Fixes

1.0.4 - 2018-03-22

Fixes

1.0.3 - 2018-03-22

Fixes

1.0.2 - 2018-03-22

Fixes

1.0.1 - 2018-03-21

Fixes

[1.0.0] - 2018-03-19

  • Initial release