diff --git a/README.md b/README.md index ccf96c8..7459cc5 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,22 @@ First, open environment and database require 'sbdb' Dir.mkdir 'newenv' rescue Errno::EEXIST - env = SBDB::Env.new 'newenv', SBDB::CREATE - db = env.open SBDB::Btree, 'newdb.db', :flags => SBDB::CREATE + env = SBDB::Env.new 'newenv', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION + db = env.btree 'newdb.db', :flags => SBDB::CREATE It works nearly like a Ruby-Hash: db['key'] = 'value' - db['key'] # => 'value' - db.to_hash # => {'key'=>'value'} - db.map {|k, v| [k, v].join ' => '} # => ["key => value"] - db.count # => 1 + db['key'] # => 'value' + db.to_hash # => {'key'=>'value'} + db.map {|k, v| "k => v" } # => ["key => value"] + db.count # => 1 + db.each {|k,v| puts "#{k}: #{v}" } -SBDB::DB#each uses a SBDB::Cursor: +`SBDB::DB#each` uses a `SBDB::Cursor`: cursor = db.cursor - cursor.each {|k,v| puts "#{k}: ${v}" } + cursor.each {|k,v| puts "#{k}: #{v}" } **Don't forget to close everything, you've opened!** @@ -47,10 +48,14 @@ SBDB::DB#each uses a SBDB::Cursor: But you can use a *lambda* to ensure to close everything: - SBDB::Env.new( 'newenv', SBDB::CREATE) do |env| + SBDB::Env.new( 'newenv', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION) do |env| env.open SBDB::Btree, 'newdb.db', :flags => SBDB::CREATE do |db| db.to_hash end end -SBDB::DB#to_hash creates a cursor and close it later. +`SBDB::DB#to_hash` creates a cursor and close it later. + +Tip: + + Signal.trap 'EXIT', env.method( :close) diff --git a/Rakefile b/Rakefile index 60d7e66..424d295 100644 --- a/Rakefile +++ b/Rakefile @@ -15,6 +15,7 @@ begin gem.files = %w[AUTHORS README.md VERSION lib/**/*.rb test/**/*.rb] gem.require_paths = %w[lib] gem.add_dependency 'bdb' + gem.add_dependency 'ref' end Jeweler::GemcutterTasks.new rescue LoadError diff --git a/VERSION b/VERSION index 3f543b7..2cfabea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.10.1 +0.0.11 diff --git a/lib/sbdb.rb b/lib/sbdb.rb index d796a06..2b3ab6f 100644 --- a/lib/sbdb.rb +++ b/lib/sbdb.rb @@ -1,4 +1,5 @@ require 'bdb' +require 'ref' require 'sbdb/environment' require 'sbdb/db' require 'sbdb/cursor'