rubinius-compatible; ref.gem. README: INIT_TRANSACTION

This commit is contained in:
Denis Knauf 2011-08-25 13:48:26 +02:00
parent bfe13fcce8
commit 6c686eb2d3
4 changed files with 18 additions and 11 deletions

View file

@ -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)

View file

@ -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

View file

@ -1 +1 @@
0.0.10.1
0.0.11

View file

@ -1,4 +1,5 @@
require 'bdb'
require 'ref'
require 'sbdb/environment'
require 'sbdb/db'
require 'sbdb/cursor'