开发者社区> 镜像站> NPM> save-json
save-json
json file persistance engine for save
Last updated 6 years ago by confuser .
BSD-2-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install save-json 
SYNC missed versions from official npm registry.

save-json

Build Status

JSON based file persistance engine for save using lodash _.where style find queries.

Installation

npm install save-json

Usage

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

Current Tags

  • 0.2.1                                ...           latest (6 years ago)

3 Versions

  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (6)
Dependents (0)
None