{"id":13929311,"url":"https://github.com/e-e-e/hyper-graph-db","last_synced_at":"2025-05-01T18:30:37.274Z","repository":{"id":57269975,"uuid":"113034061","full_name":"e-e-e/hyper-graph-db","owner":"e-e-e","description":"A distributed graph database built upon hyperdb.","archived":false,"fork":false,"pushed_at":"2020-05-23T11:45:47.000Z","size":714,"stargazers_count":63,"open_issues_count":7,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-21T00:36:32.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e-e-e.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"licenses/HYPER_GRAPH_DB_LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-04T11:26:26.000Z","updated_at":"2025-03-19T08:37:24.000Z","dependencies_parsed_at":"2022-08-25T05:51:59.677Z","dependency_job_id":null,"html_url":"https://github.com/e-e-e/hyper-graph-db","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-e-e%2Fhyper-graph-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-e-e%2Fhyper-graph-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-e-e%2Fhyper-graph-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-e-e%2Fhyper-graph-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-e-e","download_url":"https://codeload.github.com/e-e-e/hyper-graph-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251924587,"owners_count":21665998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T18:02:15.308Z","updated_at":"2025-05-01T18:30:36.819Z","avatar_url":"https://github.com/e-e-e.png","language":"JavaScript","readme":"# hyper-graph-db\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/e-e-e/hyper-graph-db.svg)](https://greenkeeper.io/)\n\n[![Build Status](https://travis-ci.org/e-e-e/hyper-graph-db.svg?branch=master)](https://travis-ci.org/e-e-e/hyper-graph-db) [![Coverage Status](https://coveralls.io/repos/github/e-e-e/hyper-graph-db/badge.svg?branch=master)](https://coveralls.io/github/e-e-e/hyper-graph-db?branch=master)\n\nhyper-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).\n\nLike 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.\n\n## install\n\n```\nnpm install hyper-graph-db\n```\n\nThis requires node v6.x.x or greater.\n\n## basic usage\n\n```js\nvar hypergraph = require('hyper-graph-db')\n\nvar db = hypergraph('./my.db', { valueEncoding: 'utf-8' })\n\nvar triple = { subject: 'a', predicate: 'b', object: 'c' }\n\ndb.put(triple, function (err) {\n  if (err) throw err\n  db.get({ subject: 'a' }, function(err, list) {\n    console.log(list)\n  });\n})\n```\n\n## API\n\n#### `var db = hypergraph(storage, [key], [options])`\n\nReturns an instance of hyper-graph-db. Arguments are passed directly to hyperdb, look at its constructor [API](https://github.com/mafintosh/hyperdb#var-db--hyperdbstorage-key-options) for configuration options.\n\nStorage argument can be a Hyperdb instance, a filepath, or a storage object. For an example of storage type objects look at [dat-storage](https://github.com/datproject/dat-storage).\n\nExtra Options:\n```js\n{\n  index: 'hex' || 'tri', // 6 or 3 indices, default 'hex'\n  name: string, // name that prefixes blank nodes\n  prefixes: { // an object representing RDF namespace prefixes\n    [sorthand]: string,\n  },\n}\n```\n\nThe prefix option can be used to further reduce db size, as it will auto replace namespaced values with their prefered prefix.\n\nFor example: `{ vcard: 'http://www.w3.org/2006/vcard/ns#' }` will store `http://www.w3.org/2006/vcard/ns#given-name` as `vcard:given-name`.\n\n**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.\n\n#### `db.on('ready')`\n\n*This event is passed on from underlying hyperdb instance.*\n\nEmitted exactly once: when the db is fully ready and all static properties have\nbeen set. You do not need to wait for this when calling any async functions.\n\n#### `db.on('error', err)`\n\n*This event is passed on from underlying hyperdb instance.*\n\nEmitted if there was a critical error before `db` is ready.\n\n#### `db.put(triple, [callback])`\n\nInserts **Hexastore** formated entries for triple into the graph database.\n\n#### `var stream = db.putStream(triple)`\n\nReturns a writable stream.\n\n#### `db.get(triple, [options], callback)`\n\nReturns 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'.\n\nOptions:\n```js\n{\n  limit: number, // limit number of triples returned\n  offset: number, // offset returned\n  filter: function (triple) { return bool }, // filter the results\n}\n```\n\n#### `db.del(triple, [callback])`\n\nRemove triples indices from the graph database.\n\n#### `var stream = db.delStream(triple)`\n\nReturns a writable stream for removing entries.\n\n#### `var stream = db.getStream(triple, [options])`\n\nReturns a readable stream of all matching triples.\n\nAllowed options:\n```js\n{\n  limit: number, // limit number of triples returned\n  offset: number, // offset returned\n  filter: function (triple) { return bool }, // filter the results\n}\n```\n\n#### `db.query(query, callback)`\n\nAllows for querying the graph with [SPARQL](https://www.w3.org/TR/sparql11-protocol/) queries.\nReturns all entries that match the query.\n\nSPARQL queries are implemented using [sparql-iterator](https://github.com/e-e-e/sparql-iterator) - a fork of [Linked Data Fragments Client](https://github.com/LinkedDataFragments/Client.js).\n\n#### `var stream = db.queryStream(query)`\n\nReturns a stream of results from the SPARQL query.\n\n#### `db.search(patterns, [options], callback)`\n\nAllows for Basic Graph Patterns searches where all patterns must match.\nExpects patterns to be an array of triple options of the form:\n\n```js\n{\n  subject: String || Variable, // required\n  predicate: String || Variable, // required\n  object: String || Variable, // required\n  filter: Function, // optional\n}\n```\n\nAllowed options:\n```js\n{\n  limit: number, // limit number of results returned\n}\n```\n\nfilter: function (triple) { return bool },\n\n```js\ndb.put([{\n    subject: 'matteo',\n    predicate: 'friend',\n    object: 'daniele'\n  }, {\n    subject: 'daniele',\n    predicate: 'friend',\n    object: 'matteo'\n  }, {\n    subject: 'daniele',\n    predicate: 'friend',\n    object: 'marco'\n  }, {\n    subject: 'lucio',\n    predicate: 'friend',\n    object: 'matteo'\n  }, {\n    subject: 'lucio',\n    predicate: 'friend',\n    object: 'marco'\n  }, {\n    subject: 'marco',\n    predicate: 'friend',\n    object: 'davide'\n  }], () =\u003e {\n\n  const stream = db.search([{\n    subject: 'matteo',\n    predicate: 'friend',\n    object: db.v('x')\n  }, {\n    subject: db.v('x'),\n    predicate: 'friend',\n    object: db.v('y')\n  }, {\n    subject: db.v('y'),\n    predicate: 'friend',\n    object: 'davide'\n  }], (err, results) =\u003e {\n    if (err) throw err\n    console.log(results)\n  })\n})\n```\n\n#### `var stream = db.searchStream(queries)`\n\nReturns search results as a stream.\n\n#### `db.graphVersion()`\n\nReturns the version of hyper-graph-db that created the db.\n\n#### `db.indexType()`\n\nReturns the type of index which the graph is configured to use: `hex` or `tri`.\n\n#### `db.name()`\n\nReturns the name used for blank nodes when searching the db.\n\n#### `db.prefixes()`\n\nReturns an object representing the RDF prefixes used by the db.\n\n","funding_links":[],"categories":["others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-e-e%2Fhyper-graph-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe-e-e%2Fhyper-graph-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe-e-e%2Fhyper-graph-db/lists"}