GithubHelp home page GithubHelp logo

doc.js's Introduction

Doc.js

Document storage and processing via map-reduce.

Notes

  • Documents here means JSON objects with a required id and revision field.

Usage

See the tests in test/spec/docSpec.js for more complete examples.

  • Include this script
  • Create a new store:

var store = new Doc.store();

  • Put some documents in it:
store.save({id:123, name:"Aela"});
store.open(123);
store.remove(123);
store.unRemove(123);
  • Create, run, and view results of map-reduce views on the data. A map function receives each doc, one at a time. A reduce function receives the concatenated results of it's corresponding map function accross all documents:
var map = function(doc){
        var words = doc.bio.split(" "),
            emits = [];
        words.forEach(function(word){
          emits.push({key:word.toLowerCase(), value:1});
        });
        return emits;
      },
      reduce = function(mapResults){
        var r = {}, count = 1;
        mapResults.forEach(function(kvPair){
          if (r.hasOwnProperty(kvPair.key)) { r[kvPair.key] += 1; }
          else {  r[kvPair.key] = 1; }
        });
        return r;
      };
store.saveView({id : "wordCount", map : map, reduce : reduce});

Persistence (WIP)

Doc offers a variety of persistence mechanisms, and can be readily extended to include your own. When a doc store is created, it can be passed a Doc.Backend object.

var store = new Doc.Store({backend = new Doc.RiakBackend()});

Included backends:

  • Doc.DefaultBackend (not persisted)
  • Doc.RiakBackend (TBI)
  • Doc.CouchBackend (TBI)
  • Doc.DynamoBackend (TBI)
  • Doc.LocalStoreBackend (TBI)

You can also create your own:

var myBackend = new Doc.Backend({
  save : function(doc){...},
  open : function(id){...}
  ...
});
var store = new Doc.Store(myBackend);

Doc expects your backend to implement:

  • save(doc)
  • open(id)
  • remove(id)
  • WIP

doc.js's People

Contributors

drobbins avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.