level-relation
relations and joins between sublevels
Installing
npm install level-relation
Example
var level = ;var sublevel = ;var indexing = ;var relation = ; var top = ;var db = ; // create some sublevelsvar users = db;var posts = db; // enable indexing;; // index some propertiesusersindex'username';postsindex'title'; // create some entriesvar user = username: 'john' ;var post = title: 'foobar' ; users;
API
relation(a, b)
Create a relation job.
relation(db).have(name)
Creates a stream factory for db
for relations name
with b
.
This is also added implicitly when a new relation is created.
Example:
;var p = usersposts;
put(x).in(y, name)
Puts x
in y
relations of name
.
Example:
put(x).in(y, name).and(y).in(x, name)
Creates a dual relation.
Example:
del(x).from(y, name)
Deletes relation name
between x
with y
.
Example:
del(x).from(y, name).and(y).from(x, name)
Deletes a dual relation.
Example:
end(fn)
Executes batch job and callbacks fn
.
Example:
;
name.by(x[, options])
Creates a ReadStream for name
relations by x
.
Options:
keys=false
{Boolean} when true, stream keys without resolvingordered=true
{Boolean} preserve insertion order
Examples:
// will resolve every relation and stream the foreign objects// ordered by the insertion time (slowest)var p = usersposts; // will resolve every relation and stream the foreign objects// unordered (bit faster)var p = usersposts; // will only stream the foreign keys, ordered by time (fast)var p = usersposts; // only gets foreign keys, not ordered by time (fastest)var p = usersposts;
License
MIT