{"id":20564620,"url":"https://github.com/yjs/y-leveldb","last_synced_at":"2025-04-12T22:17:53.283Z","repository":{"id":10203629,"uuid":"64942809","full_name":"yjs/y-leveldb","owner":"yjs","description":"LevelDB database adapter for Yjs","archived":false,"fork":false,"pushed_at":"2024-01-30T19:51:03.000Z","size":216,"stargazers_count":104,"open_issues_count":7,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T22:17:49.241Z","etag":null,"topics":["yjs","yjs-database"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":"dmonad","patreon":null,"open_collective":"y-collective","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-08-04T14:47:48.000Z","updated_at":"2025-03-23T02:49:39.000Z","dependencies_parsed_at":"2024-02-23T00:47:06.196Z","dependency_job_id":null,"html_url":"https://github.com/yjs/y-leveldb","commit_stats":{"total_commits":29,"total_committers":6,"mean_commits":4.833333333333333,"dds":0.6206896551724138,"last_synced_commit":"f469a7d1a78bbff792ab4d840aca4480049a5053"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-leveldb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-leveldb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-leveldb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjs%2Fy-leveldb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjs","download_url":"https://codeload.github.com/yjs/y-leveldb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637786,"owners_count":21137538,"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":["yjs","yjs-database"],"created_at":"2024-11-16T04:28:11.825Z","updated_at":"2025-04-12T22:17:53.256Z","avatar_url":"https://github.com/yjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/dmonad","https://opencollective.com/y-collective"],"categories":[],"sub_categories":[],"readme":"# LevelDB database adapter for [Yjs](https://github.com/yjs/yjs)\n\nLevelDB is a fast embedded database. It is the underlying technology of IndexedDB.\n\nInternally, y-leveldb uses [`level`](https://github.com/Level/level) which\nallows to exchange the storage medium for a different supported database.\nHence this adapter also supports rocksdb, lmdb, and many more..\n\n* Persistent storage for the server\n* Exchangeable storage medium\n* Can be used in [y-websocket](https://github.com/yjs/y-websocket)\n* A single y-leveldb instance can handle many documents.\n\n## Use it\n\n```sh\nnpm install y-leveldb --save\n```\n\n```js\nimport * as Y from 'yjs'\nimport { LeveldbPersistence } from 'y-leveldb'\n\nconst persistence = new LeveldbPersistence('./storage-location')\n\nconst ydoc = new Y.Doc()\nydoc.getArray('arr').insert(0, [1, 2, 3])\nydoc.getArray('arr').toArray() // =\u003e [1, 2, 3]\n\n// store document updates retrieved from other clients\npersistence.storeUpdate('my-doc', Y.encodeStateAsUpdate(ydoc))\n\n// when you want to sync, or store data to a database,\n// retrieve the temporary Y.Doc to consume data\nconst ydocPersisted = await persistence.getYDoc('my-doc')\nydocPersisted.getArray('arr') // [1, 2, 3]\n```\n\n## API\n\n### `persistence = LeveldbPersistence(storageLocation, [{ [level] }])`\n\nCreate a y-leveldb persistence instance.\n\nYou can use any levelup-compatible adapter.\n\n```js\nimport { LeveldbPersistence } from 'y-leveldb'\nimport level from 'level-mem'\n\nconst persistence = new LeveldbPersistence('./storage-location', { level })\n```\n\n#### `persistence.getYDoc(docName: string): Promise\u003cY.Doc\u003e`\n\nCreate a Y.Doc instance with the data persisted in leveldb. Use this to\ntemporarily create a Yjs document to sync changes or extract data.\n\n#### `persistence.storeUpdate(docName: string, update: Uint8Array): Promise`\n\nStore a single document update to the database.\n\n#### `persistence.getStateVector(docName: string): Promise\u003cUint8Array\u003e`\n\nThe state vector (describing the state of the persisted document - see\n[Yjs docs](https://github.com/yjs/yjs#Document-Updates)) is maintained in a separate\nfield and constantly updated.\n\nThis allows you to sync changes without actually creating a Yjs document.\n\n#### `persistence.getDiff(docName: string, stateVector: Uint8Array): Promise\u003cUint8Array\u003e`\n\nGet the differences directly from the database. The same as\n`Y.encodeStateAsUpdate(ydoc, stateVector)`.\n\n#### `persistence.clearDocument(docName: string): Promise`\n\nDelete a document, and all associated data from the database.\n\n#### `persistence.setMeta(docName: string, metaKey: string, value: any): Promise`\n\nPersist some meta information in the database and associate it with a document.\nIt is up to you what you store here. You could, for example, store credentials\nhere.\n\n#### `persistence.getMeta(docName: string, metaKey: string): Promise\u003cany|undefined\u003e`\n\nRetrieve a store meta value from the database. Returns undefined if the\n`metaKey` doesn't exist.\n\n#### `persistence.delMeta(docName: string, metaKey: string): Promise`\n\nDelete a store meta value.\n\n#### `persistence.getAllDocNames(docName: string): Promise\u003cArray\u003cstring\u003e\u003e`\n\nRetrieve the names of all stored documents.\n\n#### `persistence.getAllDocStateVectors(docName: string): Promise\u003cArray\u003c{ name:string,clock:number,sv:Uint8Array}`\n\nRetrieve the state vectors of all stored documents. You can use this to sync\ntwo y-leveldb instances.\n\nNote: The state vectors might be outdated if the associated document is not\nyet flushed. So use with caution.\n\n#### `persistence.flushDocument(docName: string): Promise` (dev only)\n\nInternally y-leveldb stores incremental updates. You can merge all document\nupdates to a single entry. You probably never have to use this.\n\n## License\n\ny-leveldb is licensed under the [MIT License](./LICENSE).\n\n\u003ckevin.jahns@protonmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-leveldb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjs%2Fy-leveldb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjs%2Fy-leveldb/lists"}