npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsondbfs

v1.0.3

Published

JSON Filesystem Database.

Downloads

568

Readme

JSON DB FS

Build Status Test Coverage Code Climate Dependency Status

NPM version NPM downloads

README

JSON FileSystem Database is a JSON Document database, such as MongoDB. All methods are asynchronous and accessing / filtering is executed in parallel using async. Currently supports 2 types of data drivers: Memory and Disk. Memory driver is very performant. It is possible to flush data to disk (configurable). Disk driver is less performant. Holds all data in disk, and reads/writes everytime you interact with the collection. Is implemented with Pessimistic Transaction Locking approach. Based on Jalalhejazi, jsonfs.

Dependencies

Internal unique ids generated with node-uuid. Object utilities with underscore. Methods implemented using asynchronous and parallel strategies with async. Pessimistic transaction locking is performed using lockfile. Criteria queries on JSON objects Mongo style json-criteria.

API

  var JSONDBFSDriver = require('jsondbfs');
  var database;

  // receives an array containing the collections you want to create / use ['Users', 'Others']
  // existing collections will be attached
  JSONDBFSDriver.connect(['Users'], {path: '/path/to/store/collections', driver: 'memory'}, function(err, db){
    database = db;
  });

  // now the collection can be accessed in the database object: 'database['Users'].insert' or 'database.Users.insert'

  database.Users.insert({name: 'Manuel', roles: ['Admin', 'Super']}, function(err, document){
    // inserts the document and returns it representation in the database (including the internal id)
    ...
  });

  database.Users.count(function(err, count){
    // returns the length of the collection
    ...
  });

  database.Users.count({name: 'Manuel'}, function(err, count){
    // returns the number of documents matching that criteria
    ...
  });

  database.Users.update({name: 'Manuel'}, {name: 'Manuel Martins', token: 'xsf32S123ss'}, function(err, result){
    // updates a specified document based on a criteria
    // result is { nMatched: 1, nModified: 1, nUpserted: 0 }
    ...
  });

  database.Users.findAndModify({name: 'Manuel Martins'}, {name: 'Manuel Martins', token: 'f32S123'}, {retObj: true}, function(err, result){
    // updates a specified document based on a criteria
    // result is the updated document
    // withou retObj info on updated / insert { nMatched: 1, nModified: 1, nUpserted: 0 } is returned
    ...
  });

  database.Users.find(function(err, documents){
    // returns everything since there is no criteria specified
    ...
  });

  database.Users.find({name: 'John'},function(err, documents){
    // returns an array with the elements that match the criteria
    ...
  });

  database.Users.findOne({name: 'John'},function(err, document){
    // returns the first document that matches the criteria
    ...
  });

  database.Users.remove({name: 'Manuel'}, function(err, success){
    // returns true if records were removed
    ...
  });

Support for Query and Projection Operators:

    database.Users.findOne({
      identities: {
        $elemMatch: {
          id: identity.id,
          provider: identity.provider
        }
      }
    }, function (err, document) {
      // returns the first document that matches the criteria inside an array of identities
      ...
    });

    database.Collection.find({
      quantity: { $gt: 25 }
    }, function (err, documents) {
      // returns the documents that matches the criteria
      ...
    });

    ...

Support provided using json-criteria.

Options

// Driver options
var JSONDBFSDriver = require('jsondbfs');
var database;

// driver options
var driverOptions = {
 path: '/path/to/store/collections',
 driver: 'memory',
 memory: {
    flush: true,
    flushInterval: 10000
  }
 };
JSONDBFSDriver.connect(['Collection'], driverOptions, callback);
...

// Collection options
database.Collection.update(criteria, updateCriteria, {upsert: false, multi: true, retObj: true}, callback);
database.Collection.findAndModify(criteria, updateCriteria, {upsert: false, multi: true, retObj: true}, callback);
database.Collection.find(criteria, {multi: false}, callback);
database.Collection.remove(criteria, {multi: false}, callback);

Driver options

When initializing the Driver you can pass 4 options:

options.path - The path to store the db collection files. Defaults to '/tmp/'.
options.driver - One of ['memory', 'disk'], defaults to 'disk'.
options.memory.flush - If you want to flush the memory to disk. Only used if driver is 'memory'. Defaults to 'false'.
options.memory.flushInterval - Time interval to flush memory to disk. Only used if driver is 'memory'. Defaults to '10000'ms. (10s)

Collections options

When updating a record you can pass 3 options:

options.upsert - If record is not found and this options is set to true, a new record will be created. Accepts a boolean 'true' or 'false'. Defaults to 'false'.
options.multi - Should update multiple records if they match. Accepts a boolean 'true' or 'false'. Defaults to 'true'.
options.retObj - Set to true if you want to return the updated object, otherwise a stats object is returned with info on updated records (as with MongoDB).

When removing or finding you can pass 1 option:

options.multi - Should update multiple records if they match. Accepts a boolean 'true' or 'false'. Defaults to 'true'.

Please check the tests for more details.

License

Apache License, Version 2.0