{"id":15483420,"url":"https://github.com/hackergrrl/hyperdb-index","last_synced_at":"2026-01-12T05:59:38.288Z","repository":{"id":143880760,"uuid":"102788811","full_name":"hackergrrl/hyperdb-index","owner":"hackergrrl","description":"Build a realtime index over a hyperdb.","archived":false,"fork":false,"pushed_at":"2018-02-28T00:30:30.000Z","size":46,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T08:23:13.101Z","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/hackergrrl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-07T21:48:13.000Z","updated_at":"2023-09-08T17:29:41.000Z","dependencies_parsed_at":"2023-07-23T20:45:27.822Z","dependency_job_id":null,"html_url":"https://github.com/hackergrrl/hyperdb-index","commit_stats":null,"previous_names":["noffle/hyperdb-index"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/hackergrrl/hyperdb-index","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fhyperdb-index","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fhyperdb-index/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fhyperdb-index/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fhyperdb-index/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackergrrl","download_url":"https://codeload.github.com/hackergrrl/hyperdb-index/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fhyperdb-index/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274998792,"owners_count":25388205,"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","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-02T05:15:23.493Z","updated_at":"2026-01-12T05:59:33.270Z","avatar_url":"https://github.com/hackergrrl.png","language":"JavaScript","readme":"# hyperdb-index\n\n\u003e Build an incremental index over a [hyperdb][hyperdb].\n\n*If you're planning on using LevelDB for storage, consider the wrapper module\n[hyperdb-index-level](https://github.com/noffle/hyperdb-index-level).*\n\nDepends on `hyperdb@2.0.0` or later for the `createHistoryStream` API.\n\n## Usage\n\nLet's build an index that tracks all `node`s in a [spatial point\nstore](https://github.com/noffle/grid-point-store), for fast bounding box\nqueries:\n\n```js\nvar index = require('hyperdb-index')\nvar hyperdb = require('hyperdb')\nvar ram = require('random-access-memory')\nvar GeoStore = require('grid-point-store')\nvar memdb = require('memdb')\n\n//------------------------------------------------------------------------------\n\nvar db = hyperdb(ram, { valueEncoding: 'json' })\nvar geo = GeoStore(memdb())\n\nvar idx = index(db, {\n  processFn: processFn,\n  getVersion: getVersion,\n  setVersion: setVersion\n})\n\nvar pending = 0\nfor (var i = 0; i \u003c 5; i++) {\n  pending++\n  db.put('/nodes/' + i, { type: 'node', lat: i, lon: -i*2 }, function () {\n    if (!--pending) query()\n  })\n}\n\nfunction query () {\n  idx.ready(function () {\n    geo.query([[-10, -10], [10, 10]], function (err, nodes) {\n      console.log('query', nodes)\n    })\n  })\n}\n\n//------------------------------------------------------------------------------\n\nvar now = null\nfunction getVersion (cb) {\n  cb(null, now)\n}\nfunction setVersion (version, cb) {\n  now = version\n  cb(null)\n}\nfunction processFn (cur, prev, next) {\n  if (cur.value.type === 'node') {\n    var v = parseInt(cur.name.split('/')[cur.name.split('/').length - 1])\n    console.log('process', cur.value)\n    geo.insert([cur.value.lat, cur.value.lon], v, next)\n  } else {\n    next(null)\n  }\n}\n```\n\noutputs\n\n```\nprocess { type: 'node', lat: 0, lon: 0 }\nprocess { type: 'node', lat: 4, lon: -8 }\nprocess { type: 'node', lat: 3, lon: -6 }\nprocess { type: 'node', lat: 1, lon: -2 }\nprocess { type: 'node', lat: 2, lon: -4 }\nquery [ { lat: 4, lon: -8, value: 4 },\n  { lat: 3, lon: -6, value: 3 },\n  { lat: 2, lon: -4, value: 2 },\n  { lat: 1, lon: -2, value: 1 },\n  { lat: 0, lon: 0, value: 0 } ]\n```\n\nSo here `hyperdb-index` is acting like a bridge between the raw point data in\n`hyperdb` and the much more efficient point storage module `grid-point-store`.\n\n## API\n\n```js\nvar index = require('hyperdb-index')\n```\n\n### var idx = index(db, opts)\n\nCreate a new index. `db` is a [hyperdb][hyperdb] instance.\n\nIt is the module consumer's responsibility to store the indexer's version of\nwhat entry it's indexed `db` up to. The module consumer controls this by\nimplementing the functions `opts.getVersion` and `opts.setVersion` (see\nbelow).\n\nValid `opts` include:\n\n- `opts.processFn` (required): a function to be called to process a new entry in\n  `db`. The expected function signature is `function (kv, oldKv, next)`, where\n  `kv` is of the form `{ key: '...', value: {} }`, `oldKv` is its previous value\n  (`null` if none), and `next` is a callback to call when processing of that\n  key-value pair is complete.\n- `opts.getVersion` (required): a function that will be called to retrieve the\n  current version of the [hyperdb][hyperdb]. It has the signature `function\n  (cb)` and expects a [hyperdb version\n  buffer](https://github.com/mafintosh/hyperdb/#dbversioncb).\n- `opts.setVersion` (required): a function that will be called to store the\n  current version of the hyperdb. It has the signature `function (version,\n  cb)`. Call `cb` once you've stored the version object.\n- `opts.prefix` (optional): a key prefix to index. If not given, the root key\n  `'/'` is assumed.\n\n### idx.ready(cb)\n\nRegisters the callback `cb` to fire when the indexes have \"caught up\" to the\nlatest known change in the hyperdb. The `cb` function fires exactly once. You\nmay call `idx.ready()` multiple times with different functions.\n\n## Install\n\nWith [npm](https://npmjs.org/) installed, run\n\n```\n$ npm install hyperdb-index\n```\n\n## See Also\n\n- [hyperlog-index](https://github.com/substack/hyperlog-index)\n\n## License\n\nISC\n\n[hyperdb]: https://github.com/mafintosh/hyperdb\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fhyperdb-index","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackergrrl%2Fhyperdb-index","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fhyperdb-index/lists"}