| Class BDB::Common |
|
Implement common methods for access to data
| Methods |
| Public Class methods |
| open(name = nil, subname = nil, flags = 0, mode = 0, options = {}) |
open the database
The flags value must be set to 0 or by bitwise inclusively OR‘ing together one or more of the following values
The DB_TRUNCATE flag cannot be transaction protected, and it is an error to specify it in a transaction protected environment.
set_append_recno will be called with (key, value) and it must return nil or the modified value
set_encrypt take an Array as arguments with the values [password, flags], where flags can be 0 or BDB::ENCRYPT_AES
Proc given to set_bt_compare, set_bt_prefix, set_dup_compare, set_h_hash, set_store_key set_fetch_key, set_store_value, set_fetch_value set_feedback and set_append_recno can be also specified as a method (replace the prefix set_ with bdb_)
For example
module BDB
class Btreesort < Btree
def bdb_bt_compare(a, b)
b.downcase <=> a.downcase
end
end
end
| create(name = nil, subname = nil, flags = 0, mode = 0, options = {}) |
same than open
| new(name = nil, subname = nil, flags = 0, mode = 0, options = {}) |
same than open
| remove(name, subname = nil) |
Removes the database (or subdatabase) represented by the name and subname combination.
If no subdatabase is specified, the physical file represented by name is removed, incidentally removing all subdatabases that it contained.
| db_remove(name, subname = nil) |
same than remove
| unlink(name, subname = nil) |
same than remove
| upgrade(name) |
Upgrade the database
| db_upgrade(name) |
same than upgrade
| Public Instance methods |
| self([key]) |
Returns the value corresponding the key
| associate(db, flag = 0) {|db, key, value| ...} |
associate a secondary index db
flag can have the value BDB::RDONLY
The block must return the new key, or Qfalse in this case the secondary index will not contain any reference to key/value
| cache_priority() |
return the current priority value
| cache_priority=(value) |
set the priority value : can be BDB::PRIORITY_VERY_LOW, BDB::PRIORITY_LOW, BDB::PRIORITY_DEFAULT, BDB::PRIORITY_HIGH or BDB::PRIORITY_VERY_HIGH
| feedback=(proc) |
monitor the progress of some operations
| get(key, flags = 0) |
Returns the value correspondind the key
flags can have the values BDB::GET_BOTH, BDB::SET_RECNO or BDB::RMW
In presence of duplicates it will return the first data item, use
duplicates if you want all duplicates (see also #each_dup)
| db_get(key, flags = 0) |
same than get
| fetch(key, flags = 0) |
same than get
| pget(key, flags = 0) |
Returns the primary key and the value corresponding to key in the secondary index
only with >= 3.3.11
| self([key] = value) |
Stores the value associating with key
If nil is given as the value, the association from the key will be removed.
| put(key, value, flags = 0) |
Stores the value associating with key
If nil is given as the value, the association from the key will be removed. It return the object deleted or nil if the specified key don’t exist.
flags can have the value DBD::NOOVERWRITE, in this case it will return nil if the specified key exist, otherwise true
| db_put(key, value, flags = 0) |
same than put
| store(key, value, flags = 0) |
same than put
| append(key, value) |
Append the value associating with key
| db_append(key, value) |
same than append
| byteswapped?() |
Return if the underlying database is in host order
| get_byteswapped() |
same than byteswapped?
| clear_partial() |
Clear partial set.
| partial_clear() |
same than clear_partial
| close(flags = 0) |
Closes the file.
| db_close(flags = 0) |
same than close
| count(key) |
Return the count of duplicate for key
| dup_count(key) |
same than count
| cursor(flags = 0) |
Open a new cursor.
| db_cursor(flags = 0) |
same than cursor
| database() |
Return the subname
| subname() |
same than database
| delete(key) |
Removes the association from the key.
It return the object deleted or nil if the specified key don’t exist.
| db_del(key) |
same than delete
| delete_if(set = nil) {|key, value| ...} |
Deletes associations if the evaluation of the block returns true.
set
| reject!(set = nil) {|key, value| ...} |
same than delete_if
| duplicates(key , assoc = true) |
Return an array of all duplicate associations for key
if assoc is false return only the values.
| each(set = nil, bulk = 0, "flags" => 0) {|key, value| ...} |
Iterates over associations.
set bulk
| each_pair(set = nil, bulk = 0) {|key, value| ...} |
same than each
| each_dup(key, bulk = 0) {|key, value| ...} |
Iterates over each duplicate associations for key
bulk
| each_dup_value(key, bulk = 0) {|value| ...} |
Iterates over each duplicate values for key
bulk
| each_key(set = nil, bulk = 0) {|key| ...} |
Iterates over keys.
set bulk
| each_primary(set = nil) {|skey, pkey, pvalue| ...} |
Iterates over secondary indexes and give secondary key, primary key and value
| each_value(set = nil, bulk = 0) {|value| ...} |
Iterates over values.
set bulk
| empty?() |
Returns true if the database is empty.
| filename() |
Return the name of the file
| has_key?(key) |
Returns true if the association from the key exists.
| key?(key) |
same than has_key?
| include?(key) |
same than has_key?
| member?(key) |
same than has_key?
| has_both?(key, value) |
Returns true if the association from key is value
| both?(key, value) |
same than has_both?
| has_value?(value) |
Returns true if the association to the value exists.
| value?(value) |
same than has_value?
| index(value) |
Returns the first key associated with value
| indexes(value1, value2, ) |
Returns the keys associated with value1, value2, …
| join(cursor , flag = 0) {|key, value| ...} |
Perform a join. cursor is an array of BDB::Cursor
| keys() |
Returns the array of the keys in the database
| length() |
Returns the number of association in the database.
| size() |
same than length
| log_register(name) |
The log_register function registers a file name.
| log_unregister() |
The log_unregister function unregisters a file name.
| reject() {|key, value| ...} |
Create an hash without the associations if the evaluation of the block returns true.
| reverse_each(set = nil) {|key, value| ...} |
Iterates over associations in reverse order
set
| reverse_each_pair(set = nil) {|key, value| ...} |
same than reverse_each
| reverse_each_key(set = nil) {|key| ...} |
Iterates over keys in reverse order
set
| reverse_each_primary(set = nil) {|skey, pkey, pvalue| ...} |
Iterates over secondary indexes in reverse order and give secondary key, primary key and value
| reverse_each_value(set = nil) {|value| ...} |
Iterates over values in reverse order.
set
| set_partial(len, offset) |
Set the partial value len and offset
| stat() |
Return database statistics.
| to_a() |
Return an array of all associations [key, value]
| to_hash() |
Return an hash of all associations {key => value}
| truncate() |
Empty a database
| clear() |
same than truncate
| values() |
Returns the array of the values in the database.
| verify(file = nil, flags = 0) |
Verify the integrity of the DB file, and optionnally output the key/data to file (file must respond to to_io)
| log_register(name) |
The log_register function registers a file name.
| log_unregister() |
The log_unregister function unregisters a file name.