@carbon-io/leafnode
Sync driver for MongoDB
Last updated 3 years ago by gregbanks .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @carbon-io/leafnode 
SYNC missed versions from official npm registry.

leafnode

Build Status

leafnode is a "synchronous" MongoDB driver. It is a wrapper around node-mongodb-native implemented using the node-fibers co-routine library.

leafnode is currently experimental and in alpha.

Example:

var connect = require('@carbon-io/leafnode').connect;

try {
   var db = connect("mongodb://localhost:27017/mydb");
   var c = db.getCollection("users");
   var results = c.find({"firstName" : "Joe"}).toArray();
   console.log(results);
} catch e {
   console.log(e);
}

No callbacks needed. If an error occurs an exception is thrown.

We say "synchronous" because leafnode code execution is still asynchronous under the hood, but uses Fibers to provide a synchronous programming interface. One should therefore note that many functions and methods of this driver actually yield control to the event loop during execution. For more on Fibers see the documenentation here.

Installation

Using npm

% cd <your-app>
% npm install leafnode

From git

% git clone git@github.com:objectlabs/leafnode.git
% cd <your-app>
% npm install <path-to-leafnode>

To run unit tests

% node ./test/all.js

Using leafnode in your code

In order to use leafnode you need to properly bootstrap your application by creating a Fiber for the code to run in.

The basic idea is as follows:

require('fibers');

Fiber(function() {
  //do stuff
}).run();

In practice you will want to do this at the beginning of a command line program or, if using an application toolkit like express, as you process each request. One nice way of achieving this in express is to add a middleware function that wraps request handling in a Fiber.

app.use(function(req, res, next) {
   Fiber(function() {
      next();
   }).run();
});

Open issues

  • Support for options in MongoDB URI uneven

Current Tags

  • 0.5.2                                ...           latest (3 years ago)

23 Versions

  • 0.5.2                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.7                                ...           3 years ago
  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           3 years ago
  • 0.4.4                                ...           3 years ago
  • 0.4.3                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.3                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Downloads
Today 0
This Week 24
This Month 24
Last Day 1
Last Week 0
Last Month 23
Dependencies (5)
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |