zazuko / query-rdf-data-cube

Explore or query RDF Data Cubes with a JavaScript API, without writing SPARQL.
https://zazuko.github.io/query-rdf-data-cube/
9 stars 2 forks source link

Use arrays for multiple filters (and .select too?) #35

Closed jstcki closed 4 years ago

jstcki commented 4 years ago

It would be convenient if multiple filters could be applied at once (i.e. use an array of filters). Constructing select is also a bit awkward Currently I have to do this:

let query = cube.query();

for (const f of filters) {
    query = query.filter(f);
}

While for .select(), I need an object (with a concrete Component):

for (const [key, iri] of fields) {
  query = query.select({
    [key]: [...measures, ...dimensions].find(m => m.iri.value === iri)!
  });
}

// and then:
await query.execute()

An improved API for the case where we have a list of fields to select and filters would be

cube.query()
  .select([["foo", dimFoo], ["bar", dimBar]]) // Similar to new Map(...)
  .filter([dimFoo.equals("baz")])
vhf commented 4 years ago

That's a great suggestion, I went with the API you suggested:

cube.query()
  .select([["foo", dimFoo], ["bar", dimBar]])
  .filter([dimFoo.equals("baz")])

Published as v0.3.0.