A little bit docu
This commit is contained in:
parent
d7a8384fc8
commit
b6254035a6
32
README
32
README
|
@ -1,33 +1,23 @@
|
|||
Bdb
|
||||
===
|
||||
= Dependencies
|
||||
|
||||
== Bdb
|
||||
|
||||
Your need first this library:
|
||||
|
||||
http://github.com/DenisKnauf/bdb
|
||||
|
||||
Download
|
||||
========
|
||||
= Download
|
||||
|
||||
via git:
|
||||
|
||||
git clone git://github.com/DenisKnauf/sbdb.git
|
||||
|
||||
Installation
|
||||
============
|
||||
= Installation
|
||||
|
||||
gem build sbdb.gemspec
|
||||
gem install sbdb-*.gem
|
||||
|
||||
or:
|
||||
|
||||
gem install sbdb --source http://github.com/DenisKnauf/sbdb/raw/master/sbdb-0.0.5.gem
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
Doesn't exist yet.
|
||||
|
||||
Usage
|
||||
=====
|
||||
= Usage
|
||||
|
||||
First, open environment and database
|
||||
|
||||
|
@ -44,18 +34,18 @@ It works nearly like a Ruby-Hash:
|
|||
db.map {|k, v| [k, v].join ' => '} # => ["key => value"]
|
||||
db.count # => 1
|
||||
|
||||
*SBDB::DB#each* uses a *SBDB::Cursor*:
|
||||
SBDB::DB#each uses a SBDB::Cursor:
|
||||
|
||||
cursor = db.cursor
|
||||
cursor.each {|k,v| puts "#{k}: ${v}" }
|
||||
|
||||
Don't forget to close everything, you opened!
|
||||
<strong>Don't forget to close everything, you've opened!</strong>
|
||||
|
||||
cursor.close
|
||||
db.close
|
||||
env.close
|
||||
|
||||
But you can use a *lambda* to ensure to close everything:
|
||||
But you can use a <em>lambda</em> to ensure to close everything:
|
||||
|
||||
SBDB::Env.new( 'newenv', SBDB::CREATE) do |env|
|
||||
env.open SBDB::Btree, 'newdb.db', 'mynewdb', SBDB::CREATE do |db|
|
||||
|
@ -63,4 +53,4 @@ But you can use a *lambda* to ensure to close everything:
|
|||
end
|
||||
end
|
||||
|
||||
*SBDB::DB#to_hash* creates a cursor and close it later.
|
||||
SBDB::DB#to_hash creates a cursor and close it later.
|
||||
|
|
|
@ -8,7 +8,11 @@ module SBDB
|
|||
INIT_LOG = Bdb::DB_INIT_LOG
|
||||
INIT_MPOOL = Bdb::DB_INIT_MPOOL
|
||||
|
||||
# Environments are for storing one or more databases and are important
|
||||
# if you want to work with more than one process on one database.
|
||||
# You needn't use Environment, but it's usefull.
|
||||
class Environment
|
||||
# returns the Bdb-object.
|
||||
def bdb_object
|
||||
@env
|
||||
end
|
||||
|
@ -31,6 +35,8 @@ module SBDB
|
|||
nil
|
||||
end
|
||||
|
||||
# Close the Environment.
|
||||
# First you should close all databases!
|
||||
def close
|
||||
@env.close
|
||||
end
|
||||
|
@ -39,6 +45,8 @@ module SBDB
|
|||
alias open new
|
||||
end
|
||||
|
||||
# Opens a Database.
|
||||
# see SBDB::DB, SBDB::Btree, SBDB::Hash, SBDB::Recno, SBDB::Queue
|
||||
def open type, *p, &e
|
||||
p[5] = self
|
||||
type.new *p, &e
|
||||
|
|
Loading…
Reference in a new issue