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
202 stars 14 forks source link

More level-ish interface? #31

Closed jmatsushita closed 7 years ago

jmatsushita commented 7 years ago

Hi there,

Just giving a try to node-quadstore and I wonder if it would make sense to provide a more level-ish interface to allow getting a store instance with:

var level = require('level');
var quadstore = require('quadstore').Quadstore;
var db = level(DB_PATH);
var store = quadstore(db);

const quads = [
    {subject: 's', predicate: 'p', object: 'o', graph: 'g'}
];

store.put(quads, (putErr) => {});

Allowing this to work with level-sublevel would also follow.

Cheers,

Jun

jacoscaz commented 7 years ago

@jmatsushita thank you for your suggestion.

The reason why I opted for levelup instead of level is that I did not want leveldown to become a dependency of node-quadstore. However, it shouldn't be hard to support both an instance of level and the current path string as the first argument of the QuadStore constructor. I'll look into this soon.

jacoscaz commented 7 years ago

@jmatsushita I've implemented support for pre-instantiated level-y objects. It's currently living here: https://github.com/jacoscaz/node-quadstore/tree/level (brach level). If you're able, could you please give it a try? It should work exactly as you suggested bar the fact that some form of valueEncoding must be passed to the constructor of the level-y object. The default serialiser can be used like so:

const store = new QuadStore(level(DB_PATH, { valueEncoding: QuadStore.valueEncoding }));
jacoscaz commented 7 years ago

@jmatsushita merged into this repo.

jacoscaz commented 7 years ago

We have now released this feature in version 2.1.1. Closing this one, bugs should go into dedicated issues.