Updating from the command line


On this page

    Comunica SPARQL (@comunica/query-sparql) allow you to initiate queries to update data in a certain store. In this guide, we will build upon the guide on querying from the command line, and show how you can not only read, but also update data.

    At the time of writing, not all possible destination types may be supported yet.

    1. Updating one source

    Using the comunica-sparql command line tool, you can invoke not only read queries, but also update queries.

    Assuming you pass just one source, this source will also be assumed to be the destination for update queries.

    For example, the following query appends a single triple to https://example.org/myfile.ttl:

    $ comunica-sparql https://example.org/myfile.ttl \
        "INSERT DATA { <ex:s> <ex:p> <ex:o> }"
    
    Given a URL, Comunica will automatically detect the type of destinations and handle it accordingly.

    As output, ok will be printed if the update was successful:

    ok
    

    2. Updating a different destination

    While Comunica supports querying over multiple sources, it only supports updating a single destination.

    Therefore, if you are querying over multiple sources, but you want to pass the results to a single destination, then you must explicitly define this destination using the --to option.

    For example, the following query takes the first 100 triples from 3 sources, and inserts them into https://example.org/myfile.ttl:

    $ comunica-sparql https://fragments.dbpedia.org/2016-04/en \
        https://www.rubensworks.net/ \
        https://ruben.verborgh.org/profile/ \
        --to https://example.org/myfile.ttl \
        "INSERT { ?s ?p ?o. } WHERE { SELECT * WHERE { ?s ?p ?o } LIMIT 100 }"
    
    The type of destination is here also automatically detected, and can also be overridden.