Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmis1000/lowdb-split-json-adapter
A lowdb adapter that split data into multi JSON files instead of only one
https://github.com/mmis1000/lowdb-split-json-adapter
Last synced: about 2 months ago
JSON representation
A lowdb adapter that split data into multi JSON files instead of only one
- Host: GitHub
- URL: https://github.com/mmis1000/lowdb-split-json-adapter
- Owner: mmis1000
- Created: 2020-07-22T08:36:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T04:15:36.000Z (over 1 year ago)
- Last Synced: 2024-04-14T22:53:52.774Z (9 months ago)
- Language: JavaScript
- Size: 409 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lowdb split JSON adapter
Unlike the original FileSync adapter from lowdb.
This adapter split the JSON into multi files.
And add additional template support.
So you can have multi small JSON file instead of a giant one that lag your editor when mock large Services.## Options
```ts
type AdapterOptions = {
// This must be a object and not array
defaultValue?: any
// customize encode method
serialize?: any => string
// customize decode method
deserialize?: string => any
}class SplitJSONAdapter {
/**
* @param dirPath path to the directory that store JSON files
* @param options optional options
*/
constructor (dirPath: string, options: AdapterOptions = {}) {}
}
```## Storage structure
Each field was a single json file, and the usage is determined by the file extension.
Available extensions:
1. .json
1. type: regular field
2. mode: r/w
2. .template.json
1. type: template a single field
2. mode: r
3. .template.js
1. type: template a single field.
Value of `module.exports` was used
2. mode: r
4. .snapshot.json
1. type: storage when try to write into read only `.template` field
2. mode: r/w
5. .js
1. type: template a single field.
Value of `module.exports` was used.
Value was **not** persistent into disk as `.snapshot.json`.
2. mode: r### When read the following dir
```txt
a.json
b.template.json
c.template.js
d.js
```Will result in
```js
const object = {
a: [/* ... */],
b: [/* ... */],
c: [/* ... */],
d: [/* ... */]
}
```### When you save above object the into the above dir
You get
```txt
a.json // in place modified
b.template.json // untouched
b.snapshot.json // new
c.template.js // untouched
c.snapshot.json // new
d.js // untouched
```So you can simply exclude all `.snapshot.json` from git or whatever while still keep it locally persistent.