@triply/triplydb
    Preparing search index...

    Class SparqlResults

    The results of an ad-hoc SPARQL query, in whichever form the query asks for.

    Returned by Dataset.sparqlQuery and Service.sparqlQuery. Never constructed directly.

    Nothing is sent until you pick a form: bindings() for a SELECT, statements() for a CONSTRUCT or DESCRIBE, boolean() for an ASK, or toFile to write the results out. Asking for a form the query cannot answer in is rejected rather than coerced.

    Every failure arrives as a rejected promise from one of those, including a query that does not parse — obtaining this object never throws on its own.

    Each form is a single request that returns the whole result set, so — unlike the paginated collections elsewhere in this library — this object can be used more than once, and every call runs the query again.

    const bindings = await dataset.sparqlQuery("select * { ?s ?p ?o } limit 10").bindings()
    
    Index
    • The results as variable bindings, for a SELECT query.

      Returns Promise<Binding[]>

      A binding maps each variable name to the lexical form of its value, and leaves out the variables the row does not bind.

      If the query is not a SELECT, or does not parse.

    • The single answer to an ASK query.

      Returns Promise<boolean>

      If the query is not an ASK, or does not parse.

    • The results as RDF statements, for a CONSTRUCT or DESCRIBE query.

      Returns Promise<Quad[]>

      If the query is neither a CONSTRUCT nor a DESCRIBE, or does not parse.

    • Runs the query and writes its results to a file.

      Parameters

      • destinationPath: string

        Where to write. Any existing file is overwritten.

      • Optionalopts: { compressed?: boolean }

        Set compressed to gzip the output as it is written. Defaults to gzipping when destinationPath ends in .gz.

      Returns Promise<void>

      The query's form decides the serialisation, not the file name you pass: a SELECT or ASK is written as TSV, and a CONSTRUCT or DESCRIBE as N-Triples. Pick an extension that matches, because nothing here will correct it for you.

      If the query does not parse, or the destination's directory does not exist.

      await dataset.sparqlQuery("construct { ?s ?p ?o } where { ?s ?p ?o }").toFile("out.nt.gz")