|
1 | | -# hyperdb-graph [wip] |
| 1 | +# hyper-graph-db |
2 | 2 |
|
3 | | -Not much to see here. Just a spec, failing tests, and the intention to experiment. |
| 3 | +[](https://travis-ci.org/e-e-e/hyper-graph-db) [](https://coveralls.io/github/e-e-e/hyper-graph-db?branch=master) |
4 | 4 |
|
5 | | -The aim is to build a graph database on top of [hyperdb](https://github.com/mafintosh/hyperdb). |
| 5 | +hyper-graph-db is a graph database on top of [hyperdb](https://github.com/mafintosh/hyperdb). It interface and test specs have been adapted from [LevelGraph](https://github.com/levelgraph/levelgraph). |
6 | 6 |
|
7 | | -The test spec is adapted from [LevelGraph](https://github.com/levelgraph/levelgraph). |
| 7 | +Like LevelGraph, **hyper-graph-db** follows the **Hexastore** approach as presented in the article: [Hexastore: sextuple indexing for semantic web data management C Weiss, P Karras, A Bernstein - Proceedings of the VLDB Endowment, 2008](http://www.vldb.org/pvldb/1/1453965.pdf). As such hyper-graph-db uses six indices for every triple in order to access them as fast as it is possible. |
| 8 | + |
| 9 | +## install |
| 10 | + |
| 11 | +``` |
| 12 | +npm install hyper-graph-db |
| 13 | +``` |
| 14 | + |
| 15 | +This requires node v6.x.x or greater. |
| 16 | + |
| 17 | +## basic usage |
| 18 | + |
| 19 | +```js |
| 20 | +var hyperdb = require('hyperdb') |
| 21 | +var hypergraph = require('hyper-graph-db') |
| 22 | + |
| 23 | +var db = hypergraph(hyperdb('./my.db', {valueEncoding: 'utf-8'})) |
| 24 | + |
| 25 | +var triple = { subject: 'a', predicate: 'b', object: 'c' } |
| 26 | + |
| 27 | +db.put(triple, function (err) { |
| 28 | + if (err) throw err |
| 29 | + db.get({ subject: 'a' }, function(err, list) { |
| 30 | + console.log(list) |
| 31 | + }); |
| 32 | +}) |
| 33 | +``` |
| 34 | + |
| 35 | +## API |
| 36 | + |
| 37 | +#### `var db = hypergraph(hyperdb)` |
| 38 | + |
| 39 | +Returns an instance of hyper-graph-db using the hyperdb passed to it. |
| 40 | + |
| 41 | +#### `db.put(triple, [callback])` |
| 42 | + |
| 43 | +Inserts **Hexastore** formated entries for triple into the graph database. |
| 44 | + |
| 45 | +#### `var stream = db.putStream(triple)` |
| 46 | + |
| 47 | +Returns a writable stream. **This is not yet implemented!** |
| 48 | + |
| 49 | +#### `db.get(triple, [callback])` |
| 50 | + |
| 51 | +Returns all entries that match the triple. This allows for partial pattern-matching. For example `{ subject: 'a' })`, will return all triples with subject equal to 'a'. |
| 52 | + |
| 53 | +#### `db.del(triple, [callback])` |
| 54 | + |
| 55 | +Remove triples indices from the graph database. |
| 56 | + |
| 57 | +#### `var stream = db.delStream(triple)` |
| 58 | + |
| 59 | +Returns a writable stream for removing entries. **This is not yet implemented!** |
| 60 | + |
| 61 | +#### `var stream = db.getStream(triple)` |
| 62 | + |
| 63 | +Returns a readable stream of all matching triples. |
| 64 | + |
| 65 | +#### `db.search(queries, [callback])` |
| 66 | + |
| 67 | +Allows for Basic Graph Patterns searches where all queries must match. |
| 68 | + |
| 69 | +```js |
| 70 | +db.put([{ |
| 71 | + subject: 'matteo', |
| 72 | + predicate: 'friend', |
| 73 | + object: 'daniele' |
| 74 | + }, { |
| 75 | + subject: 'daniele', |
| 76 | + predicate: 'friend', |
| 77 | + object: 'matteo' |
| 78 | + }, { |
| 79 | + subject: 'daniele', |
| 80 | + predicate: 'friend', |
| 81 | + object: 'marco' |
| 82 | + }, { |
| 83 | + subject: 'lucio', |
| 84 | + predicate: 'friend', |
| 85 | + object: 'matteo' |
| 86 | + }, { |
| 87 | + subject: 'lucio', |
| 88 | + predicate: 'friend', |
| 89 | + object: 'marco' |
| 90 | + }, { |
| 91 | + subject: 'marco', |
| 92 | + predicate: 'friend', |
| 93 | + object: 'davide' |
| 94 | + }], () => { |
| 95 | + |
| 96 | + const stream = db.search([{ |
| 97 | + subject: 'matteo', |
| 98 | + predicate: 'friend', |
| 99 | + object: db.v('x') |
| 100 | + }, { |
| 101 | + subject: db.v('x'), |
| 102 | + predicate: 'friend', |
| 103 | + object: db.v('y') |
| 104 | + }, { |
| 105 | + subject: db.v('y'), |
| 106 | + predicate: 'friend', |
| 107 | + object: 'davide' |
| 108 | + }], (err, results) => { |
| 109 | + if (err) throw err |
| 110 | + console.log(results) |
| 111 | + }) |
| 112 | +}) |
| 113 | +``` |
| 114 | + |
| 115 | +#### `var stream = db.searchStream(queries)` |
| 116 | + |
| 117 | +Returns search results as a stream. |
0 commit comments