
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Fast in-process in-memory key-value store for node with snapshot and AOF persistance and CouchDB-style map-reduce views. Just make sure your data fits in memory, currently I wouldn't recommend divan for a dataset with more than 500K docs.
npm install divan
index.js
// Make a divan with local compacted append-only and snapshot files,
// namespace works in the same way it does for `dirty`:
var divan = require ( 'divan' ),
db = divan.cwd ( 'friends' );
// Save some docs, generating your own id-s:
db.save ({ _id : 'don1', type : 'person', name : 'Don', gender : 'male' });
db.save ({ _id : 'samantha', type : 'person', name : 'Sam', gender : 'female' });
db.save ({ _id : 'i.v.a.n', type : 'person', name : 'Ivan', gender : 'male' });
// These will be flushed to the AOF and then later compacted as a db snapshot.
// Now register a view:
db.addView
(
'gender/count',
divan.mr
(
function ( doc, emit )
{
if ( doc.type === 'person' )
emit ( doc.gender, 1 );
},
function ( k, v )
{
var i, n = v.length, sum = 0;
for ( i = 0; i < n; i ++ ) sum += v [ i ];
return sum;
}
)
);
// Query the view:
db.view ( 'gender/count', { group : true }, function ( err, data )
{
data.rows.forEach ( function ( row )
{
console.log ( row.key, row.value );
});
});
// Outputs:
// female 1
// male 2
You can add views via db.addView
or by parsing a directory of
design files via db.design(path)
.
The design-files can either be
.json files of couchdb-design-doc flavour,
or .js files that export objects
with map
and reduce
methods.
Note that when using .js docs,
map
functions need to accept
the emit
function as the second parameter.
Everything but group_level
and include_docs
.
Instead of populating views immediately,
divan maps all documents for a view on first .query()
.
This means that you can have as many designs as you want,
if you only use a few the rest won't eat up memory.
Also, reduce results are only computed and cached for the ranges of a view that you actually access. Once warmed up, the caches are invalidated and rebuilt very quickly on writes and deletes, because divan caches intermediate reduce results.
Brief, if you want to fully warm up a reduce view,
query it with group=true
or group=false
(depending on whether you'll ever use ungrouped results),
without specifying a key-range.
db.forEach(func)
db.addView("view-name", ["source-view", "other-source-view"], viewObj)
you can perform chained map/reduce, although its not optimized and is really slow right now.MIT
FAQs
persistant key-value store for node with CouchDB-style views
The npm package divan receives a total of 0 weekly downloads. As such, divan popularity was classified as not popular.
We found that divan demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.