Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
save
Advanced tools
Readme
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:
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
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)
})
var save = require('save')
Save by default returns an in memory engine which means you can unit test your models independently from your database. name
is the name of your model.
Possible options are:
idProperty
. Defaults to _id
for mongodblogger
. Defaults to console logging: { info: console.info, verbose: console.info }
engine
. Persistence engine to use, defaults to memory engine: require(./memory-engine)
Creates a new entity.
cb
called with cb(err, savedObject)
.
Reads a single entity with an idProperty
of id
.
cb
called with cb(err, readObject)
.
Updates a single entity. Optionally overwrites the entire entity, by default just extends it with the new values.
cb
called with cb(err, readObject)
.
Deletes one entity.
Returns an error if the object can not be found.
cb
called with cb(err)
.
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)
.
Performs a find on the data.
cb
called with cb(err, foundObjectsArray)
.
Performs a find on the data and limits the result set to 1.
cb
called with cb(err, foundObject)
.
Performs a count by query.
cb
called with cb(err, count)
.
Provides access to the idProperty
. Mostly used for testing.
This event fires with cb(object)
where object
is the item that will be created.
This event fires with cb(object)
where object
is the item that has been created.
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.
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.
This event fires with cb(id)
where id
is the item that will be deleted.
This event fires with cb(id)
where id
is the item that has been deleted.
This event fires with cb(query)
where query
is the query used to deleteMany
.
This event fires with cb(query)
where query
is the query that has used deleteMany
.
This event fires with cb(id)
where id
is the item that has been read.
This event fires with cb(query)
where query
is the query used to find
.
This event fires with cb(query)
where query
is the query used to findOne
.
This event fires with cb(query)
where query
is the query used to count
.
This event fires with cb(err)
where err
is any error that may have occured.
Paul Serby follow me on twitter @serby
Licenced under the New BSD License
FAQs
A simple CRUD based persistence abstraction for storing objects to any backend data store. eg. Memory, MongoDB, Redis, CouchDB, Postgres, Punch Card etc.
The npm package save receives a total of 78,291 weekly downloads. As such, save popularity was classified as popular.
We found that save demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.