https://github.com/confuser/save-json
JSON persistance engine for save
https://github.com/confuser/save-json
Last synced: 2 days ago
JSON representation
JSON persistance engine for save
- Host: GitHub
- URL: https://github.com/confuser/save-json
- Owner: confuser
- License: bsd-3-clause
- Created: 2013-11-10T11:13:07.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-11T10:06:16.000Z (almost 12 years ago)
- Last Synced: 2025-09-20T04:49:42.116Z (9 months ago)
- Language: JavaScript
- Size: 201 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# save-json
[](https://travis-ci.org/confuser/save-json)
JSON based file persistance engine for [save](https://npmjs.org/package/save) using lodash _.where style find queries.
## Installation
npm install save-json
## Usage
```js
var save = require('save') // npm install save
, saveJson = require('..')
// Create a save object and pass in a saveJson engine.
var contactStore = save('Contact', { engine: saveJson('contact.json') })
// Ensure the engine initialised correctly
if (!contactStore)
throw Error('Could not initiate json save') // Common cause is file creation issue
// Then we can create a new object.
contactStore.create({ name: 'James', email: 'jamesmortemore@gmail.com'}, function (error, contact) {
// The created 'contact' is returned and has been given an id
console.log(contact)
// Now check the contents of contact.json... magic!
})
// Lets find that object with a lodash _.where style query. Simple!
contactStore.findOne({ name: 'James' }, function (error, contact) {
// Will be the object created above
console.log(contact)
})
```
## Licence
Licensed under the [New BSD License](http://opensource.org/licenses/bsd-license.php)