Coder Social home page Coder Social logo

node-tokyocabinet's Introduction

Introduction

Tokyo Cabinet binding for Node.js. So far only implemented interfaces defined in tokyocabinet.idl.

Install

$ node-waf configure build

Warning

THIS SOFTWARE IS STILL AN ALPHA VERSION.

Sync vs. Async

Sync interface (not recommended because we are using Node.js!).

var hdb = new HDB;
// open database
var success = hdb.open('casket.tch', HDB.OWRITER | HDB.OCREAT);
if (!success) throw hdb.errmsg();
// store a value
var success = hdb.put('foo', 'bar');
if (!success) throw hdb.errmsg();
// retrieve a value
var v = hdb.get('foo'); // => 'bar'
if (v === null) throw hdb.errmsg();
sys.puts(v);

Async interface.

var hdb = new HDB;
// 'setmutex' makes database multi-thread safe
hdb.setmutex();
// open database
hdb.openAsync('casket.tch', HDB.OWRITER | HDB.OCREAT, function(err){
  if (err) throw hdb.errmsg(err);
  // store a value
  hdb.putAsync('foo', 'bar', function(err){
    if (err) throw hdb.errmsg(err);
    // retrieve a value
    hdb.get('foo', function(err, val){
      if (err) throw hdb.errmsg(err);
      sys.puts(val);
    });
  });
});
hdb.put('foo', 'bar');
var v = hdb.get('foo'); // => 'bar'

As you can see, it’s very cumbersome to write with Async APIs. I’m planning to write the Async wrapper API to make it easy to use. Or you can wrap with your preferred library (Promise, Deferred, Do, etc.)

ToDo

  • Write async wrapper.

  • More tests.

License

The MIT License Copyright © 2010 Atsushi Takayama <taka.atsushi (a) gmail.com>

node-tokyocabinet's People

Watchers

GitIan-Champion avatar  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.