Neptunium, Promethium, Manganese

    TypeScript icon, indicating that this package has built-in type declarations

    0.2.5 • Public • Published

    Oxigraph for JavaScript

    npm actions status Gitter

    This package provides a JavaScript API on top of Oxigraph, compiled with WebAssembly.

    Oxigraph is a graph database written in Rust implementing the SPARQL standard.

    Oxigraph for JavaScript is a work in progress and currently offers a simple in-memory store with SPARQL 1.1 Query and SPARQL 1.1 Update capabilities.

    The store is also able to load RDF serialized in Turtle, TriG, N-Triples, N-Quads and RDF/XML.

    It is distributed using a a NPM package that should work with nodeJS 12+.

    npm install oxigraph
    const oxigraph = require('oxigraph');


    Insert the triple <http://example/> <> "example" and log the name of <http://example/> in SPARQL:

    const { MemoryStore } = require('oxigraph');
    const store = new MemoryStore();
    const dataFactory = store.dataFactory;
    const ex = dataFactory.namedNode("http://example/");
    const schemaName = dataFactory.namedNode("");
    store.add(dataFactory.triple(ex, schemaName, dataFactory.literal("example")));
    for (binding of store.query("SELECT ?name WHERE { <http://example/> <> ?name }")) {


    Oxigraph currently provides a simple JS API. It is centered around the MemoryStore class.

    The NamedNode, BlankNode, Literal, DefaultGraph, Quad and DataFactory types are following the RDF/JS datamodel specification.

    To import MemoryStore using Node:

    const { MemoryStore } = require('oxigraph');


    MemoryStore(optional sequence<Quad>? quads) (constructor)

    const store = new MemoryStore();

    If provided, the MemoryStore will be initialized with a sequence of quads.


    Returns a DataFactory following RDF/JS datamodel specification.


    const store = new MemoryStore();
    const ex = store.dataFactory.namedNode("");
    const blank = store.dataFactory.blankNode();
    const foo = store.dataFactory.literal("foo");
    const quad = store.dataFactory.quad(blank, ex, foo);

    MemoryStore.prototype.add(Quad quad)

    Inserts a quad in the store.



    MemoryStore.prototype.delete(Quad quad)

    Removes a quad from the store.



    MemoryStore.prototype.has(Quad quad)

    Returns a boolean stating if the store contains the quad.



    MemoryStore.prototype.match(optional Term? subject, optional Term? predicate, optional Term? object, optional Term? graph)

    Returns an array with all the quads matching a given quad pattern.

    Example to get all quads in the default graph with ex for subject:

    store.match(ex, null, null, store.dataFactory.defaultGraph());

    Example to get all quads:


    MemoryStore.prototype.query(String query)

    Executes a SPARQL 1.1 Query. For SELECT queries the return type is an array of Map which keys are the bound variables and values are the values the result is bound to. For CONSTRUCT and ÐESCRIBE queries the return type is an array of Quad. For ASK queries the return type is a boolean.

    Example of SELECT query:

    for (binding of store.query("SELECT DISTINCT ?s WHERE { ?s ?p ?o }")) {

    Example of CONSTRUCT query:

    const filteredStore = new MemoryStore(store.query("CONSTRUCT { <http:/> ?p ?o } WHERE { <http:/> ?p ?o }"));

    Example of ASK query:

    if (store.query("ASK { ?s ?s ?s }")) {
        console.log("there is a triple with same subject, predicate and object");

    MemoryStore.prototype.update(String query)

    Executes a SPARQL 1.1 Update. The LOAD operation is not supported yet.

    Example of update:

    store.update("DELETE WHERE { <> ?p ?o }")

    MemoryStore.prototype.load(String data, String mimeType, NamedNode|String? baseIRI, NamedNode|BlankNode|DefaultGraph? toNamedGraph)

    Loads serialized RDF triples or quad into the store. The method arguments are:

    1. data: the serialized RDF triples or quads.
    2. mimeType: the MIME type of the serialization. See below for the supported mime types.
    3. baseIRI: the base IRI to use to resolve the relative IRIs in the serialization.
    4. toNamedGraph: for triple serialization formats, the name of the named graph the triple should be loaded to.

    The available formats are:

    Example of loading a Turtle file into the named graph <> with the base IRI

    store.load("<> <> <> .", "text/turtle", "", store.dataFactory.namedNode(""));

    MemoryStore.prototype.dump(String mimeType, NamedNode|BlankNode|DefaultGraph? fromNamedGraph)

    Returns serialized RDF triples or quad from the store. The method arguments are:

    1. mimeType: the MIME type of the serialization. See below for the supported mime types.
    2. fromNamedGraph: for triple serialization formats, the name of the named graph the triple should be loaded from.

    The available formats are:

    Example of building a Turtle file from the named graph <>:

    store.dump("text/turtle", store.dataFactory.namedNode(""));

    How to contribute

    The Oxigraph bindings are written in Rust using the Rust WASM toolkit.

    The The Rust Wasm Book is a great tutorial to get started.

    To run the tests of the JS bindings written in JS run npm test.


    This project is licensed under either of

    at your option.


    Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Futures by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


    npm i oxigraph

    DownloadsWeekly Downloads





    MIT OR Apache-2.0

    Unpacked Size

    2.44 MB

    Total Files


    Last publish


    • tpt93