quadstorejs / quadstore

A LevelDB-backed graph database for JS runtimes (Node.js, Deno, browsers, ...) supporting SPARQL queries and the RDF/JS interface.
https://github.com/quadstorejs/quadstore
MIT License
203 stars 14 forks source link

More advanced joins #41

Closed jmatsushita closed 7 years ago

jmatsushita commented 7 years ago

Hi there,

Currently I believe it's only possible to join two queries by an identical property (i.e. predicate to predicate)

It would be great to be able to join queries by joining on different fields. This kind of API would do I guess:

// QuadStore
const matchTermsA = {graph: 'g'};
const matchTermsB = {subject: 's'};
quadStore.query(matchTermsA)
    .join(quadStore.query(matchTermsB), [{ 'subject': 'graph' }]) // this would join (rather arbitrarily) a.graph == b.subject)  
    .get((err, quads) => {});

Allowing to still pass strings would keep backward compatibility, and allowing objects would enable joining by different properties.

What do you think?

Jun

jacoscaz commented 7 years ago

Hello @jmatsushita. This is a fantastic suggestion. I have a few hours of spare time coming up. I'll look into this and #40 .

jmatsushita commented 7 years ago

Great ! :)

jacoscaz commented 7 years ago

Some preliminary work about this here: https://github.com/jacoscaz/node-quadstore/blob/joins/test/quadstore.js#L586

I've had to slightly change your proposal as I needed to maintain the ordering of term names:

quadStore.query(matchTermsA)
    .join(quadStore.query(matchTermsB), ['subject'], ['graph'])
    .get((err, quads) => {});
jacoscaz commented 7 years ago

See pull request #43

jacoscaz commented 7 years ago

Closing, available on NPM in quadstore@2.2.0-alpha .