{"id":19974422,"url":"https://github.com/alanchenchen/jsondb","last_synced_at":"2025-05-04T02:32:45.938Z","repository":{"id":57096115,"uuid":"224157459","full_name":"alanchenchen/jsonDb","owner":"alanchenchen","description":"A small db controller saving with json file","archived":false,"fork":false,"pushed_at":"2019-12-05T08:37:45.000Z","size":34,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-18T20:24:36.828Z","etag":null,"topics":["db","json","json-server","jsondb","lowdb"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/alanchenchen.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}},"created_at":"2019-11-26T09:53:01.000Z","updated_at":"2021-11-29T09:32:42.000Z","dependencies_parsed_at":"2022-08-22T21:40:32.785Z","dependency_job_id":null,"html_url":"https://github.com/alanchenchen/jsonDb","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/alanchenchen%2FjsonDb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2FjsonDb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2FjsonDb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanchenchen%2FjsonDb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alanchenchen","download_url":"https://codeload.github.com/alanchenchen/jsonDb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224379845,"owners_count":17301525,"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":["db","json","json-server","jsondb","lowdb"],"created_at":"2024-11-13T03:14:58.315Z","updated_at":"2024-11-13T03:14:58.411Z","avatar_url":"https://github.com/alanchenchen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonDb\n\n\n![](https://img.shields.io/npm/v/@alanchenchen/json-db.svg)\n![](https://img.shields.io/npm/dt/@alanchenchen/json-db.svg)\n[![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/996icu/996.ICU/blob/master/LICENSE)\n\na small db controller saving with json file\n\u003e Author：Alan Chen\n\n\u003e Version: 0.0.1\n\n\u003e Date: 2019/11/27\n\n## purpose\n\n1. lowdb适用的场景，jsonDb都适用，我个人认为，这种以本地文件存储数据的插件，比较适合electron本地应用和非常轻量的server。\n2. lowdb本身没对数据读写做什么处理，它更像是一个通用的api插件，支持adapter来实现读写数据的接口。虽然兼容了browser端，但是我个人认为localstorage本身就是阻塞操作，还不如localforage集成的indexdb和websql来的高效。\n3. lowdb自带的adapter对node端处理的太过于[暴力](https://github.com/typicode/lowdb/blob/master/src/adapters/FileAsync.js)，导致在读写体积稍微大一点的json文件（[作者说是200m左右](https://github.com/typicode/lowdb#usage)）时，就会导致卡顿，甚至内存崩溃。\n4. jsonDb在对读取文件时，做了分片读取，通过jsonDb生成的`.jsonx`文件都会附带一个索引映射`.map`文件。开发者可以指定读取部分字节大小的数据到内存中，而且索引文件会同步更新，这样就避免了内存崩溃和io读取耗时太长。\n\n\u003e 其实jsonDb也可以写成lowdb的一个adapter，但是在下不太喜欢依赖太多，加上一些api可能也不好实现，因此写了一个单独的插件。\n\n## disadvantage\n\n1. 虽然jsonDb在一定程度上解决了读取大文件的耗时和内存崩溃问题，但是随着`.jsonx`文件越来越大，`.map`文件也势必越来越大，尤其当`.jsonx`文件的key超级庞大，这样就gg了。。。\n2. 原本最理想的情况是，读写都实现分片，但是在写入文件时遇到[坑](./doc/mistakes.md)了。。。\n3. lowdb由于集成了lodash，所以在处理数据上会非常好用，jsonDb没有，但是提供了一个query方法自定义查询，如果你觉得还是不够的话。自己用lodash再次处理吧。\n4. 目前不支持并发操作，后期可能会通过event emitter保证下次读取会等待当前写入完成之后再触发。\n\n## installation\n`npm install --save @alanchenchen/json-db` or `yarn add @alanchenchen/json-db`\n\n## usage\n1. `git clone https://github.com/alanchenchen/jsonDb.git`\n2. `cd jsonDb`然后`yarn`安装好依赖\n3. 接着使用下面的脚本命令即可，目前入口文件是example.ts\n\n## api\n[传送门](./doc/api.md)\n\n## scripts\n\n1. `npm start`等同于`npm run serve`,通过ts-node启动example.ts.\n2. `npm build`编译ts文件到dist目录.\n\n## license\n* Anti 996(996.ICU)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanchenchen%2Fjsondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falanchenchen%2Fjsondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanchenchen%2Fjsondb/lists"}