{"id":15592045,"url":"https://github.com/derhuerst/level-tree","last_synced_at":"2025-06-13T14:02:32.029Z","repository":{"id":57107606,"uuid":"100848064","full_name":"derhuerst/level-tree","owner":"derhuerst","description":"Store trees in a LevelDB.","archived":false,"fork":false,"pushed_at":"2020-05-03T15:56:46.000Z","size":44,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:36:51.261Z","etag":null,"topics":["level","leveldb","tree"],"latest_commit_sha":null,"homepage":"https://github.com/derhuerst/level-tree","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derhuerst.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-20T08:21:20.000Z","updated_at":"2020-05-03T15:56:29.000Z","dependencies_parsed_at":"2022-08-20T17:11:19.056Z","dependency_job_id":null,"html_url":"https://github.com/derhuerst/level-tree","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/derhuerst%2Flevel-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flevel-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flevel-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Flevel-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derhuerst","download_url":"https://codeload.github.com/derhuerst/level-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016306,"owners_count":21198828,"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":["level","leveldb","tree"],"created_at":"2024-10-02T23:53:34.314Z","updated_at":"2025-04-15T05:36:57.218Z","avatar_url":"https://github.com/derhuerst.png","language":"JavaScript","funding_links":["https://patreon.com/derhuerst"],"categories":[],"sub_categories":[],"readme":"# level-tree\n\n**Store trees in a [LevelDB](https://github.com/level/levelup).**\n\n[![npm version](https://img.shields.io/npm/v/@derhuerst/level-tree.svg)](https://www.npmjs.com/package/@derhuerst/level-tree)\n[![build status](https://img.shields.io/travis/derhuerst/level-tree.svg)](https://travis-ci.org/derhuerst/level-tree)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/level-tree.svg)\n[![chat on gitter](https://badges.gitter.im/derhuerst.svg)](https://gitter.im/derhuerst)\n[![support me on Patreon](https://img.shields.io/badge/support%20me-on%20patreon-fa7664.svg)](https://patreon.com/derhuerst)\n\n\n## Installing\n\n```shell\nnpm install @derhuerst/level-tree\n```\n\n\n## Usage\n\n```js\nconst levelTree = require('@derhuerst/level-tree')\n\nconst db = level('path/to/leveldb')\nconst tree = levelTree(db)\n\ntree.put('example', {\n\ta1: 'A1',\n\ta2: [\n\t\t'A2-0',\n\t\t{\n\t\t\tb1: 'A2-1-B1'\n\t\t}\n\t]\n}, (err) =\u003e {\n\tif (err) return console.error(err)\n\n\tdb.put('example.a2.0', 'a new value', (err) =\u003e {\n\t\tif (err) return console.error(err)\n\n\t\ttree.get('example', (err, example) =\u003e {\n\t\t\tif (err) return console.error(err)\n\n\t\t\tconsole.log(example)\n\t\t})\n\t})\n})\n```\n\n```js\n{\n\ta1: 'A1',\n\ta2: [\n\t\t'a new value',\n\t\t{\n\t\t\tb1: 'A2-1-B1'\n\t\t}\n\t]\n}\n```\n\nYou can also load `get`, `put` \u0026 `del` separately:\n\n```js\nconst createGet = require('@derhuerst/level-tree/get')\nconst createPut = require('@derhuerst/level-tree/put')\nconst createDel = require('@derhuerst/level-tree/del')\n\nconst get = createGet(db)\nconst put = createPut(db)\nconst del = createDel(db)\n```\n\n### patches\n\n`level-tree` can apply [*JSON Patch*](http://jsonpatch.com/) diffs to the tree. Using the `db` from above:\n\n```js\nconst createPatch = require('@derhuerst/level-tree/patch')\nconst patch = createPatch(db)\n\npatch('example', [\n\t{op: 'move', path: '/a3', from: '/a2/1'}\n], (err) =\u003e {\n\tif (err) return console.error(err)\n\n\ttree.get('example', (err, example) =\u003e {\n\t\tif (err) return console.error(err)\n\n\t\tconsole.log(example)\n\t})\n})\n```\n\n```js\n{\n\ta1: 'A1',\n\ta2: [\n\t\t'a new value'\n\t],\n\ta3: {\n\t\tb1: 'A2-1-B1'\n\t}\n}\n```\n\n\n## API\n\n```js\nconst tree = createTree(db)\n```\n\n`db` must be a [levelup](https://www.npmjs.com/package/levelup)-compatible database.\n\n## `tree.get(namespace, cb)`\n\nWill try to infer the tree from all keys starting with `namespace`.\n\n## `tree.put(namespace, [dryRun], data, cb)`\n\nIf `dryRun` is `true`, `cb` will be called with all [ops](https://www.npmjs.com/package/levelup#batch) to be executed. Otherwise, they will be executed.\n\n## `tree.del(namespace, [dryRun], cb)`\n\nIf `dryRun` is `true`, `cb` will be called with all [ops](https://www.npmjs.com/package/levelup#batch) to be executed. Otherwise, they will be executed.\n\nIf it fails to find any chilren under `namespace`, it will try to delete at `namespace` itself (the root so to say) as well.\n\n\n## Contributing\n\nIf you have a question or have difficulties using `level-tree`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to [the issues page](https://github.com/derhuerst/level-tree/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Flevel-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderhuerst%2Flevel-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Flevel-tree/lists"}