# egg-json-db

> 简单的json数据库

Latest version **1.0.10** (published 2021-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-json-db
pnpm add egg-json-db
yarn add egg-json-db
bun add egg-json-db
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2021-07-21 |
| First published | 2021-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mingpo |
| Keywords | egg, eggPlugin, egg-plugin, node-json-db |

## Links

- npm: https://www.npmjs.com/package/egg-json-db
- Repository: https://github.com/packaaa/egg-json-db
- Homepage: https://github.com/packaaa/egg-json-db#readme
- Issues: https://github.com/packaaa/egg-json-db/issues
- npm.io page: https://npm.io/package/egg-json-db

## Dependencies (1)

- [node-json-db](https://npm.io/package/node-json-db.md) ^1.3.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.10 (latest) — 2021-07-21
- 1.0.9 — 2021-07-19
- 1.0.8 — 2021-07-19
- 1.0.7 — 2021-07-19
- 1.0.6 — 2021-07-19
- 1.0.5 — 2021-07-19

## README

# egg-json-db

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-json-db.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-json-db
[travis-image]: https://img.shields.io/travis/eggjs/egg-json-db.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-json-db
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-json-db.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-json-db?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-json-db.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-json-db
[snyk-image]: https://snyk.io/test/npm/egg-json-db/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-json-db
[download-image]: https://img.shields.io/npm/dm/egg-json-db.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-json-db

<!--
Description here.
-->

## Install

```bash
$ npm i egg-json-db --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.jsonDb = {
  enable: true,
  package: 'egg-json-db',
};
```

## Configuration

```js
// {app_root}/config/config.default.js
exports.jsonDb = {
  // 存储路径  /test/
  savePath: '',
  // 命名
  nameSpace: 'model',
  // 加载文件夹
  loadDir: 'app/model',
  saveOnPush: true,
  humanReadable: false,
  separator: '/',
};
```

see [config/config.default.js](config/config.default.js) for more detail.

## Example

> 插件基于 node-json-db,具体方法可参考[node-json-db](https://github.com/Belphemur/node-json-db)

```js
// {app_root}/app/model/myDataBase.js
'use strict';

module.exports = app => {
  /**
   * jsonDbSchema
   * @param {*} obj | json 初始化数据，默认{}
   * @param {*} model | 生成json文件名，默认data
   * @return | JsonDB
   */
  const myDataBase = app.jsonDbSchema({ test1: 0 }, 'test1');
  return myDataBase;
};

// {app_root}/app/controller/home.js
('use strict');

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { model } = this.app;
    model.myDataBase.push('/test3', { test: 'test', json: { test: ['test'] } });
    console.log('数据：', JSON.stringify(model.myDataBase.getData('/')));
    this.ctx.body = model.myDataBase.getData('/test3');
  }
}

module.exports = HomeController;
```

## Questions & Suggestions

Please open an issue [here](https://github.com/packaaa/egg-json-db/issues).

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/egg-json-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
