Git Product home page Git Product logo

node-leveldb's Introduction

This repository is no longer maintained. node-levelup may provide what you need.

Build Status

Node-LevelDB

The leveldb library provides a persistent key value store. Keys and values are arbitrary byte arrays. The keys are ordered within the key value store according to a user-specified comparator function.

This project is node bindings to this excellent library so that node programs can either implement their own custom databases or simply use it directly as a fast, simple key/value store.

While implementing nStore, I realized there are a couple things that V8 and node are not very good at. They are heavy disk I/O and massive objects with either millions of keys or millions of sub objects.

Since LevelDB provides good primitives like MVCC and binary support (It was designed to back IndexDB in the Chrome browser), then it can be used as a base to implement things like CouchDB.

Usage

var leveldb = require('leveldb');
leveldb.open("path/to/my/db", { create_if_missing: true }, onOpen);

function onOpen(err, db) {
  var key = "mykey";
  db.put(key, "My Value!", function(err) {
    db.get(key, function(err, value) {
      console.dir(value); // prints: My Value!
      db.del(key);
    });
  });
}

Installing

To compile native code and CoffeeScript do:

npm install

Testing

To run tests do:

npm test

You can also view the current build status on Travis-CI.

Stripping the library

The leveldb library is bundled in the deps folder and is compiled in staticly. The resulting node addon is about 4mb unstripped. If you want to make it smaller, I've had success using the strip command on it which shrinks it down to about 300kb.

strip build/default/leveldb.node

Contributing

Since I am not experienced in the world of C++ and am still learning, I welcome contributions. Mainly what I need right now is someone with experience to review my code and tell me things I'm doing stupid. Maybe add a C++ best pratices note to this document.

Currently Randall Leeds (@tilgovi and one of the CouchDB commiters) has expressed interest in helping and already has commit rights to the project.

Contributors

   176  Michael Phan-Ba
    55  Nathan Landis
    39  Tim Caswell
    19  [email protected]
    15  [email protected]
    12  [email protected]
    12  Stefan Thomas
     9  Randall Leeds
     9  Carter Thaxton
     6  Damon Oehlman
     5  Hans Wennborg
     4  shinuza
     3  [email protected]
     2  Sanjay Ghemawat
     1  (no author)
     1  Paul Vorbach
     1  justmoon
     1  Gabor Cselle

node-leveldb's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-leveldb's Issues

License

There isn't a license for the project right now. LevelDB itself is New BSD licensed. I use the Apache license for my project. In any case, I think it would be a good thing to have a LICENSE file in the repo at some point.

demo/million.js is broken

When I try to run demo/million.js I get the following error:

rehanift@rehan-laptop:~/src/node-leveldb$ node demo/million.js 
Creating test database

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Argument 1 must be a string: DB.open(<filename>, <options?>, <callback?>)
    at Object.<anonymous> (/home/rehanift/src/node-leveldb/demo/million.js:6:4)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

iterator should be a stream

right now with iterator.forRange there is no way to know when the iterator has finished. ideally creating an iterator return a readable Stream

Why CoffeeScript?

Wouldn't it be more convenient to use JavaScript instead of CoffeScript for the non C++ parts?

I find it very hard to read CoffeeScript code and so do many others and would say that such an essential library use as less dependencies as possible, since it doesn't make anything easier.

What's the reason for using CoffeeScript?

Check when iterator.forEach finished

As far as I know there is currently no way to execute a callback if the iterator.forEach() method has reached limitKey.

Maybe I'm just not seeing how to do this (I'm quite new to node), but if there isn't one, would it be possible to add an additional callback (or something similar)?

[0.10] Module can't be found?

I know the 0.10 version is still in development, but thought I'd share this issue with getting the latest version to even be recognized:

package.json

{
    "dependencies":{
        "leveldb":"git://github.com/my8bird/node-leveldb.git#dev/update_0.10"
    }
}

app.js

var leveldb = require('leveldb');
console.log(leveldb);

result

$ node app.js 

module.js:340
    throw err;
          ^
Error: Cannot find module 'leveldb'

I'm not too familiar with node (yet), but the package.json file in the leveldb module indicates "main": "lib", however, after npm installs the package, there is no lib folder in the leveldb folder. Should there be? I see lib is in the .gitignore file, so I'm guessing something is supposed to build that, but what? I did get a "build" folder as part of the npm install process, however.

OS X 10.6.8, node v0.10.5, npm 1.2.18

The full NPM install log is pasted here.

Fixes for 0.8

When running the test suite this error is shown and should be resolved.

path.exists is now called fs.exists

Possible regression related to asBuffer

Some recent update in node-leveldb broke BitcoinJS:

https://github.com/bitcoinjs/bitcoinjs-server/issues/61#issuecomment-3876406

This database call is returning a string for some reason:

  var getBlockByHeight = this.getBlockByHeight =
  function getBlockByHeight(height, callback) {
    height = formatHeightKey(height);
    Step(
      function () {
        bBlockHeightIndex.get(height, true, this);
      },
      function (err, result) {
        if (err) throw err;

        console.log(Buffer.isBuffer(result), typeof result);

        if (!result) {
          this(null, null);
        } else {
          getBlockByHash(result, this);
        }
      },
      callback
    );
  };

The output of the debug statement is:

false 'string'

The result seems to be the correct result, just as a string, not as a buffer. Note that the second parameter of the get() call is true. What's even stranger: In other places asBuffer seems to work correctly.

Would you consider allowing the LevelUP team to take over "leveldb" in npm?

Since keeping up with V8 and Node changes is quite a challenge and we have a very active community around the LevelUP (JS) and LevelDOWN (C++) packages exposing LevelDB in Node perhaps you would consider allowing us to start publishing code under the "leveldb" name in npm? We get occasional bug reports about people trying to install our packages but using "leveldb" instead. There's also people new to the ecosystem who just pick the name because it's logical (e.g.).
We would bump the major version and leave historical releases intact for anyone that might still have old systems using working versions of this code.
Cheers.

makefile breaks during npm install

if you do npm install leveldb it works but if you add leveldb as a dependency in your package.json and then do npm install it fails on the coffeescript compile line of the makefile

i switched the compile line to these two lines and it succeeded for me:

coffee --bare --compile --output lib src/coffee/*.coffee
coffee --bare --compile --output lib src/coffee/leveldb/*.coffee

OS X - endian.h: No such file or directory

I'm getting a build error on Mac OS X (10.7), with node v0.6.2, when I do an npm install leveldb

/Users/john/node_modules/leveldb/deps/leveldb/port/port_posix.h:20:22: error: 
endian.h: No such file or directory

However, if I clone the source from master, it builds fine.

share the same leveldb database between nodejs cluster processes

Hi,
I know that sharing the same leveldb instance between various processes is discouraged, but I was wondering if it could work in case of node.js core cluster where only master process would update database and workers would only query db. Did anyone tried that?

Cheers,

doesn't work with node v0.8.1

node v0.8.1
npm 1.1.33
Mac OS X 10.6.8

package.json wants node ~0.6.x so I guess this is not unexpected. Any hints on how to fix this and what else could be broken?

> var leveldb = require('leveldb')
Error: dlopen(/Users/carlos/t76/node_modules/leveldb/lib/leveldb.node, 1): no suitable image found.  Did find:
    /Users/carlos/t76/node_modules/leveldb/lib/leveldb.node: mach-o, but wrong architecture
    at Object.Module._extensions..node (module.js:480:11)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/carlos/t76/node_modules/leveldb/lib/leveldb/handle.js:3:11)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Switch to gitflow repository style

Master will always be solid
develop is where in progress work goes

All "real" work on feature branches that are pulled into develop and when develop is ready it is pulled into master and npm published.

npm install fails if coffee-script is already installed

npm doesn't install coffee-script if it's already installed locally which leaves
node-leveldb's own node_modules directory empty, causing following postinstall step to fail.

> [email protected] postinstall /Users/don/dev/test/node_modules/leveldb
> ./node_modules/coffee-script/bin/coffee -b -c -o lib/ src

sh: ./node_modules/coffee-script/bin/coffee: No such file or directory

Fix build issues with node 0.10

node -v v0.10.1
node-gyp -v v0.8.5
System Darwin 12.3.0

../src/cpp/handle.cc:77:12: error: no matching function for call to 'AsyncQueue'
return AsyncQueue(op, AsyncWorker, AsyncCallback);
^~~~~~~~~~

2 warnings generated.
LIBTOOL-STATIC Release/snappy.a
CXX(target) Release/obj.target/leveldb/src/cpp/batch.o
CXX(target) Release/obj.target/leveldb/src/cpp/binding.o
CXX(target) Release/obj.target/leveldb/src/cpp/comparator.o
CXX(target) Release/obj.target/leveldb/src/cpp/handle.o
../src/cpp/handle.cc:77:12: error: no matching function for call to 'AsyncQueue'
return AsyncQueue(op, AsyncWorker, AsyncCallback);
^~~~~~~~~~
../src/cpp/handle.cc:234:12: note: in instantiation of function template specialization
'node_leveldb::JHandle::OpAsync::AsyncEnqueue<node_leveldb::JHandle::ReadAsync>' requested here
return AsyncEnqueue(op);
^
...

Random test failures

@my8bird posted the following test error:

  ✖ 1 of 41 tests failed:

  1) Iterator db.forRange() should iterate until limit key:

      actual expected

      107

  AssertionError: "107" == ""
      at i (/home/nathan/src/node-leveldb/test/iterator-test.coffee:202:18)
      at exports.Iterator.Iterator.forRange.next (/home/nathan/src/node-leveldb/lib/leveldb/iterator.js:142:9)
      at exports.Iterator.Iterator._wrapSeek (/home/nathan/src/node-leveldb/lib/leveldb/iterator.js:62:28)

I've also been getting intermittent test errors that disappear on the the next run.

@mikepb says:

The tests failures happen randomly. I haven't the time to track down the issue. There's a lot of multithreading involved, that may be the issue.

random empty keys when iterating over a database

With the latest 0.7.1 from npm I'm seing random empty keys when iterating over a database created by an earlier version of node-leveldb on node.js 0.6.x

I think it's unlikely that the database is corrupted, as it is successfully read by the earlier node-leveldb version and by a C++ program using leveldb directly.

The c++ program iterates over 269298 records and doesn't get any empty keys. Same for leveldb 0.5.5 on node.js 0.6.11, with somewhat different code

leveldb 0.7.1 on node 0.8.8 gets 269298 records as well, but between 2 and 7 of them have a empty key. The exact number depends on the run and on what I do while iterating.

It is perfectly possible I'm doing something really stupid so below's the code, unfortunately I can't share the db.
With this code - which just iterates - I get 4 empty keys all the time and always in the same positions: 1661, 6138, 22158, 114237 but that changes just by moving console.log statements around

#!/usr/bin/env node

'use strict'

var leveldb = require('leveldb');

leveldb.open('./encodingDict', {create_if_missing:true}, function(err, db) {
  if(err) {
    return cb(err);
  }

  readEncodingDict(db, function(err) {
    if(err) {
      return cb(err);
    }
    console.log('read OK');
  });
});

var encodingDict = {};

var count = 0;
function readEncodingDict(db, cb) {
  db.iterator(function(err, it) {
    if(err) {
      return cb(err);
    }

    it.first(function(err) {
      if(err) {
        return cb(err);
      }

      function goGet() {
        if(!it.valid()) {
          console.log('read', count, 'records');
                return cb(null);
        }

        it.key(function(err, key) {
          if(err) {
            return cb(err);
          }

          ++count;

          if(key === '') {
            console.log('empty key on position', count);
          }

          it.next(function(err) {
            if(err) {
              return cb(err);
            }
            process.nextTick(goGet);
          });
        });
      }

      goGet();
    });
  });
}

Collaborators wanted

justmoon, mikepb

Since you two seem to be really active and have lots of useful insight into the project I have added you both as collaborators to the GitHub repository. I do not know how this will play out but it should at least making merging changes easier since all git refs will be in the same repository. If either of you do not want to be on the "main" repository for whatever reason just let me know, no hard feelings.

Also, if either of you would like I think npm allows for multiple owners of a project. This would primarily allow you to do npm publish. Of course, we would need to be sure to sync up prior to doing such things so that bug fixes do not collide.

coffee-script needs to be installed?

Tried to npm install and got the following:

'build' finished successfully (9m42.136s)> [email protected] postinstall /home/pi/git/bblite/node_modules/leveldb> make pkgclean

coffee --bare --compile --output lib src/coffee
make: coffee: Command not found
make: *** [coffee] Error 127
npm ERR! [email protected] postinstall: make pkgclean

I did a global install coffee-script and this went away.

Current NPM module 0.5.3 won't build, looking for /home/nathan/

moon@clymene:/var/www/node-bitcoin-p2p$ sudo npm install leveldb
npm http GET https://registry.npmjs.org/leveldb
npm http 304 https://registry.npmjs.org/leveldb
npm http GET https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/coffee-script

> [email protected] install /atlas/www/node-bitcoin-p2p/node_modules/leveldb
> node-waf configure build

Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for program gcc or cc           : /usr/bin/gcc 
Checking for gcc                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : ok /usr/local 
'configure' finished successfully (0.058s)
Waf: Entering directory `/home/nathan/src/node-leveldb/build'
Waf: Leaving directory `/home/nathan/src/node-leveldb/build'
cp: cannot stat `/home/nathan/src/node-leveldb/build/Release/leveldb.node': No such file or directory
'build' finished successfully (0.007s)

> [email protected] postinstall /atlas/www/node-bitcoin-p2p/node_modules/leveldb
> ./node_modules/coffee-script/bin/coffee -b -c -o lib/ src

[email protected] ./node_modules/leveldb 
└── [email protected]

The fix is to delete the build directory:


moon@clymene:/var/www/node-bitcoin-p2p$ sudo rm -r node_modules/leveldb/build/
moon@clymene:/var/www/node-bitcoin-p2p$ cd node_modules/leveldb/
moon@clymene:/var/www/node-bitcoin-p2p/node_modules/leveldb$ sudo node-waf configure build
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for program gcc or cc           : /usr/bin/gcc 
Checking for gcc                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : ok /usr/local 
'configure' finished successfully (0.042s)
Waf: Entering directory `/atlas/www/node-bitcoin-p2p/node_modules/leveldb/build'
[ 1/47] cxx: deps/snappy/snappy.cc -> build/Release/deps/snappy/snappy_1.o
[ 2/47] cxx: deps/snappy/snappy-sinksource.cc -> build/Release/deps/snappy/snappy-sinksource_1.o
[...etc...]

You can try changing the .npmignore entry from build to build/, but I've found that even then NPM is pretty wonky about randomly including stuff. My advice is to just make a habit of rm -r build before npm publish.

leveldb submodule not working

Reported by email from Paresh Thummar [email protected]

Respected sir,
I want to install leveldb in project(In node.js). I use npm install leveldb command to install it. then i got following error.

ERR! [email protected] preinstall: `git submodule update && node-waf configure build && coffee -b -c -o lib src`
ERR! `cmd "/c" "git submodule update && node-waf configure build && coffee -b -c -o lib src"` failed with 1
ERR! 
ERR! Failed at the [email protected] preinstall script.
ERR! This is most likely a problem with the leveldb package,

What should i do?
please give me exact process to use leveldb in my script.

Thank you,

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.