Skip to content
Browse files


  • Loading branch information...
1 parent 53be4bc commit d3d6569831c42cc16a57a0b48887e726caa96611 @tokuhirom committed Dec 25, 2011
Showing with 134 additions and 5 deletions.
  1. +127 −0 README.mkdn
  2. +3 −2
  3. +2 −2 package.json
  4. +2 −1 test/test.js
127 README.mkdn
@@ -0,0 +1,127 @@
+GDBM for node.js
+ var gdbm = require('gdbm');
+ var db = new gdbm.GDBM();
+"hoge.db", 0, gdbm.GDBM_WRCREAT);
+"dan", "kogai");
+ db.fetch("dan") # => "kogai"
+ db.close();
+GDBM is a GNU’s reinterpretation of dbm. You can use it as local KVS.
+[, block_size[, flag[, mode]]])
+Open database files.
+`block_size` is the size of a single
+transfer from disk to memory. This parameter is ignored unless the file
+is a new file. The minimum size is 512. If it is less than 512, dbm
+will use the stat block size for the file system.
+`flags` can have one of the following values:
+ gdbm.GDBM_READER: reader
+ gdbm.GDBM_WRITER: writer
+ gdbm.GDBM_WRCREAT: writer - if database does not exist create new one
+ gdbm.GDBM_NEWDB: writer - create new database regardless if one exists
+The gdbm.GDBM_NOMMAP added to read_write by bitwise or instructs gdbm_open
+to disable the use of mmap(2).
+For the last three (writers of the database) the following may be added added to read_write by bitwise or: GDBM_SYNC, which causes all database operations to be synchronized to the disk, and GDBM_NOLOCK, which prevents the library from performing any locking on the database file.
+Mode is the file mode (see chmod(2) and open(2) ) if the file is created. (*Fatal_func) () is a function for dbm to call if it detects a fatal error. The only parameter of this function is a string. If the value of 0 is provided, gdbm will use a default function.
+, value[, flags])
+Key is the key data. Value is the data to be associated with the key.
+Flag can have one of the following values:
+ Insert only, generate an error if key exists;
+ Replace contents if key exists.
+If a reader calls, the return value will be -1. If called
+with GDBM_INSERT and key is in the database, the return value will be
+1. Otherwise, the return value is 0.
+NOTICE: If you store data for a key that is already in the data base,
+gdbm replaces the old data with the new data if called with
+GDBM_REPLACE. You do not get two data items for the same key and you
+do not get an error from gdbm_store.
+NOTICE: The size in gdbm is not restricted like in dbm or ndbm. Your
+data can be as large as you want.
+var str = gdbm.GDBM.prototype.fetch(key)
+Fetch the entry from database.
+Key is the key data.
+var b = gdbm.GDBM.prototype.exists(key)
+Key is the key data to search for.
+If the key is found within the database, the return value will be true.
+If nothing appropiate is found, false is returned. This routine is
+useful for checking for the existence of a record, without performing
+the memory allocation done by gdbm_fetch
+Key is the key data.
+The return value is false if the item is not present or the requester is a
+reader. The return value is true if there was a successful delete.
+It’s possible to loop over every key in the database using this method and the nextkey() method. The traversal is ordered by gdbm‘s internal hash values, and won’t be sorted by the key values. This method returns the starting key.
+Returns the key that follows key in the traversal. The following code prints every key in the database db, without having to create a list in memory that contains them all:
+ var key = db.firstkey();
+ while (key) {
+ console.log(key);
+ key = db.nextkey(key);
+ }
+When the database has been opened in fast mode, this method forces any unwritten data to be written to the disk.
+If you have had a lot of deletions and would like to shrink the space
+used by the gdbm file, this routine will reorganize the database. Gdbm
+will not shorten the length of a gdbm file except by using this reorga-
+nization. (Deleted file space will be reused.)
+Unless your database was opened with the GDBM_SYNC flag, gdbm does not
+wait for writes to be flushed to the disk before continuing. The fol-
+lowing routine can be used to guarantee that the database is physically
+written to the disk file.
@@ -11,7 +11,7 @@ using namespace node;
#define THROW(msg) return ThrowException(Exception::Error(String::New(msg)));
-#define NODE_GDBM_VERSION "1.0.1"
+#define NODE_GDBM_VERSION "1.0.2"
static Persistent<String> open_symbol;
static Persistent<String> close_symbol;
@@ -211,7 +211,7 @@ class GDBM : public node::ObjectWrap {
bool Delete(char * str, int len) {
datum key = {str, len};
- return gdbm_delete(db_, key);
+ return gdbm_delete(db_, key)==0;
static Handle<Value> Delete(const v8::Arguments& args) {
HandleScope scope;
@@ -292,6 +292,7 @@ init(Handle<Object> target) {
4 package.json
@@ -2,10 +2,10 @@
"author": "Tokuhiro Matsuno <> (",
"name": "gdbm",
"description": "gdbm for node.js",
- "version": "1.0.1",
+ "version": "1.0.2",
"url": "",
"repository": {
- "type": git",
+ "type": "git",
"url": "git://"
"scripts": {
3 test/test.js
@@ -70,7 +70,8 @@ exports.exists_delete = function (t) {
t.ok(!db.exists('dan'));'dan', 'kogai');
- db.delete('dan');
+ t.ok(db.delete('dan'));
+ t.ok(!db.delete('dan'));

0 comments on commit d3d6569

Please sign in to comment.
Something went wrong with that request. Please try again.