hyper-graph-db is a graph database on top of hyperdb. It interface and test specs have been adapted from LevelGraph.
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. As such hyper-graph-db uses six indices for every triple in order to access them as fast as it is possible.
npm install hyper-graph-db
This requires node v6.x.x or greater.
var hypergraph = require('hyper-graph-db')
var db = hypergraph('./my.db', { valueEncoding: 'utf-8' })
var triple = { subject: 'a', predicate: 'b', object: 'c' }
db.put(triple, function (err) {
if (err) throw err
db.get({ subject: 'a' }, function(err, list) {
console.log(list)
});
})
Returns an instance of hyper-graph-db. Arguments are passed directly to hyperdb, look at its constructor API for configuration options.
Storage argument can be a Hyperdb instance, a filepath, or a storage object. For an example of storage type objects look at dat-storage.
Extra Options:
{
index: 'hex' || 'tri', // 6 or 3 indices, default 'hex'
name: string, // name that prefixes blank nodes
prefixes: { // an object representing RDF namespace prefixes
[sorthand]: string,
},
}
The prefix option can be used to further reduce db size, as it will auto replace namespaced values with their prefered prefix.
For example: { vcard: 'http://www.w3.org/2006/vcard/ns#' }
will store http://www.w3.org/2006/vcard/ns#given-name
as vcard:given-name
.
Note: index
, name
, and prefixes
can only be set when a graph db is first created. When loading an existing graph these values are also loaded from the db.
This event is passed on from underlying hyperdb instance.
Emitted exactly once: when the db is fully ready and all static properties have been set. You do not need to wait for this when calling any async functions.
This event is passed on from underlying hyperdb instance.
Emitted if there was a critical error before db
is ready.
Inserts Hexastore formated entries for triple into the graph database.
Returns a writable stream.
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'.
Options:
{
limit: number, // limit number of triples returned
offset: number, // offset returned
filter: function (triple) { return bool }, // filter the results
}
Remove triples indices from the graph database.
Returns a writable stream for removing entries.
Returns a readable stream of all matching triples.
Allowed options:
{
limit: number, // limit number of triples returned
offset: number, // offset returned
filter: function (triple) { return bool }, // filter the results
}
Allows for querying the graph with SPARQL queries. Returns all entries that match the query.
SPARQL queries are implemented using sparql-iterator - a fork of Linked Data Fragments Client.
Returns a stream of results from the SPARQL query.
Allows for Basic Graph Patterns searches where all patterns must match. Expects patterns to be an array of triple options of the form:
{
subject: String || Variable, // required
predicate: String || Variable, // required
object: String || Variable, // required
filter: Function, // optional
}
Allowed options:
{
limit: number, // limit number of results returned
}
filter: function (triple) { return bool },
db.put([{
subject: 'matteo',
predicate: 'friend',
object: 'daniele'
}, {
subject: 'daniele',
predicate: 'friend',
object: 'matteo'
}, {
subject: 'daniele',
predicate: 'friend',
object: 'marco'
}, {
subject: 'lucio',
predicate: 'friend',
object: 'matteo'
}, {
subject: 'lucio',
predicate: 'friend',
object: 'marco'
}, {
subject: 'marco',
predicate: 'friend',
object: 'davide'
}], () => {
const stream = db.search([{
subject: 'matteo',
predicate: 'friend',
object: db.v('x')
}, {
subject: db.v('x'),
predicate: 'friend',
object: db.v('y')
}, {
subject: db.v('y'),
predicate: 'friend',
object: 'davide'
}], (err, results) => {
if (err) throw err
console.log(results)
})
})
Returns search results as a stream.
Returns the version of hyper-graph-db that created the db.
Returns the type of index which the graph is configured to use: hex
or tri
.
Returns the name used for blank nodes when searching the db.
Returns an object representing the RDF prefixes used by the db.