A simple CRUD based persistence abstraction for storing objects to any backend data store. eg. Memory, MongoDB, Redis, CouchDB, Postgres, Punch Card etc.
npm install save
  
save comes with a fully featured in memory engine which is super handy for testing your models.
For real world use you'll need to get one of the database powered engines:
* MongoDB
If your data store of choice isn't listed here please create an engine and send me a pull request.
To see an example of how to create an engine, please see save-mongodb.
npm install save
``js
var save = require('save')
, s = save('person')
s.on('create', function() {
console.log('New person created!')
})
s.create({ name: 'Dom' }, function(err, person) {
// Outputs { name: 'Dom', _id: 1 }
console.log(person)
})
`
`js`
var save = require('save')
is the name of your model.Possible options are:
*
idProperty. Defaults to _id for mongodb
* logger. Defaults to console logging: { info: console.info, verbose: console.info }
* engine. Persistence engine to use, defaults to memory engine: require(./memory-engine)$3
Creates a new entity.
cb called with cb(err, savedObject).$3
Reads a single entity with an idProperty of id.
cb called with cb(err, readObject).$3
Updates a single entity. Optionally overwrites the entire entity, by default just extends it with the new values.
cb called with cb(err, readObject).$3
Deletes one entity.
Returns an error if the object can not be found.
cb called with cb(err).$3
Deletes entities based on a query.
Performs a find by query, then calls delete for each item returned
Returns an error if no items match the query.
cb called with cb(err).$3
Performs a find on the data.
cb called with cb(err, foundObjectsArray).$3
Performs a find on the data and limits the result set to 1.
cb called with cb(err, foundObject).$3
Performs a count by query.
cb called with cb(err, count).$3
Provides access to the idProperty. Mostly used for testing.Events
$3
This event fires with cb(object) where object is the item that will be created.$3
This event fires with cb(object) where object is the item that has been created.$3
This event fires with cb(object, overwrite) where object is the item that will be updated and overwrite is whether the object is to be overwritten or extended.$3
This event fires with cb(object, overwrite) where object is the item that has been updated and overwrite is whether the object is to be overwritten or extended.$3
This event fires with cb(id) where id is the item that will be deleted.$3
This event fires with cb(id) where id is the item that has been deleted.$3
This event fires with cb(query) where query is the query used to deleteMany.$3
This event fires with cb(query) where query is the query that has used deleteMany.$3
This event fires with cb(id) where id is the item that has been read.$3
This event fires with cb(query) where query is the query used to find.$3
This event fires with cb(query) where query is the query used to findOne.$3
This event fires with cb(query) where query is the query used to count.$3
This event fires with cb(err) where err` is any error that may have occured.