Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steverandy/json-datastore
File-based JSON datastore
https://github.com/steverandy/json-datastore
datastore file json
Last synced: 15 days ago
JSON representation
File-based JSON datastore
- Host: GitHub
- URL: https://github.com/steverandy/json-datastore
- Owner: steverandy
- License: mit
- Created: 2016-09-04T03:07:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-09T05:16:43.000Z (over 6 years ago)
- Last Synced: 2024-10-05T17:46:17.025Z (3 months ago)
- Topics: datastore, file, json
- Language: JavaScript
- Size: 118 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-datastore
File-based JSON datastore.
## Install
```
$ npm install --save json-datastore
```## Usage
``` javascript
let datastore = require("json-datastore")// Write to a datastore
datastore.write("/path/to/datastore", {
_id: "global-config", checkUpdates: false
}).then(doNextThing)// Write to users collection
datastore.write("/path/to/datastore/users", {
_id: 1, name: "Steve"
}).then(doNextThing)// Read by id in users collection
datastore.read("/path/to/datastore/users", {_id: 1}).then(user => {
doNextThing(user)
})// Read all in users collection
datastore.read("/path/to/datastore/users").then(users => {
doNextThing(users)
})// Read all in users collection in descending order
datastore.read("/path/to/datastore/users", {}, {
descending: true
}).then(users => {
doNextThing(users)
})// Remove all in users collection
datastore.remove("/path/to/datastore/users").then(doNextThing)
```## API
**datastore.read(path, query, options)**
Read one or many documents in the specified path.**datastore.write(path, object, options)**
Write object to a JSON file in the specified path. An `_id` is generated by default for the object and used as the file name. You can partition the store by writing to sub-directories.**datastore.remove(path, query)**
Remove one or many documents in the specified path.## License
[MIT License](./LICENSE)