You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

anti-db

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anti-db

Plain old JS object that saves itself to disk

1.0.0
latest
Source
npm
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

anti-db

Anti-db takes the idea of a database fronted by a memory cache and reverses it, for maximum performance. The storage is a POJO (plain old JS object), which is saved to disk upon program exit. Optionally, the data can be saved to disk periodically.

###Initializing an object from disk

var antidb = require('anti-db')();
var myobj = antidb.obj('./some.json');
myobj.hey = 'there';
// no need to call save(), automatically saved to disk on exit ./some.json

Use array instead of object

var myarr = antidb.obj('./somearr.json', []);
myarr.push(1970);

Save obj to disk periodically, just to be safer

var antidb = require('anti-db')(10000);  // every 10 sec.
var myobj = antidb.obj('./some.json');
myobj.hey = 'there';

Periodical mode

Will not attempt any saving to disk on SIGINT EXIT etc.., and just save to disk periodically.

var antidb = require('anti-db')(period = 10000, nosaveonexit = 1});  // every 10 sec.
var myobj = antidb.obj('./some.json');
myobj.hey = 'there';

Provide a default object / model and seal the object from further property additions

var antidb = require('anti-db')();
var myobj = antidb.obj('./some.json', {name: 'Chris', age: 21});

Override loading and saving of objects - Use as cache for other data sources

// Using a CSV as backing file

var antidb = require('anti-db')();
antidb.loadFunc = function(name, type){
	var csv_arr = fs.readFileSync(name).toString().split(/\n/);
	// put into JSON object
	return obj;
}
antidb.saveFunc = function(name, o){
	require('json2csv')({data: json, fields: ['car', 'price', 'color']}, function(err, csv) {
	  if (err) console.log(err);
	  fs.writeFile('file.csv', csv, function(err) {
	    if (err) throw err;
	    console.log('file saved');
	  });
	});
}

Debug mode

Do this when running your app..

$ debug=1 node myapp

Keywords

util

FAQs

Package last updated on 24 Nov 2013

Did you know?

Socket

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.

Install

Related posts