BerkeleyDB::Manager - General purpose BerkeleyDB wrapper
use BerkeleyDB::Manager; my $m = BerkeleyDB::Manager->new( home => Path::Class::Dir->new( ... ), # if you want to use rel paths db_class => "BerkeleyDB::Hash", # the default class for new DBs ); my $db = $m->open_db( file => "foo" ); # defaults $m->txn_do(sub { $db->db_put("foo", "bar"); die "error!"; # rolls back });
This object provides a convenience wrapper for BerkeleyDB
The path to pass as -Home to BerkeleyDB::Env->new.
-Home
BerkeleyDB::Env->new
If provided the file arguments to open_db should be relative paths.
file
open_db
If not provided, BerkeleyDB will use the current working directory for transaction journals, etc.
Whether DB_CREATE is passed to Env or instantiate_db by default. Defaults to true.
DB_CREATE
Env
instantiate_db
Whether or not to enable transactions.
Defaults to true.
Whether or not a top level transaction is automatically created by BerkeleyDB. Defaults to true.
If you turn this off note that all database handles must be opened inside a transaction, unless transactions are disabled.
If true (the default) DB_REGISTER and DB_RECOVER are enabled in the flags to the env.
DB_REGISTER
DB_RECOVER
This will enable automatic recovery in case of a crash.
Enables DB_DUP in -Properties by default, allowing duplicate keys in the db.
DB_DUP
-Properties
Enables DB_DUPSORT in -Properties by default.
DB_DUPSORT
The default class to use when instantiating new DB objects. Defaults to BerkeleyDB::Btree.
Flags to pass to the env. Overrides transactions, create and recover.
transactions
create
recover
Flags to pass to instantiate_db. Overrides create and autocommit.
autocommit
Properties to pass to instantiate_db. Overrides dup and dupsort.
dup
dupsort
The hash of currently open dbs.
Fetch a database handle, opening it as necessary.
If name is provided, it is used as the key in open_dbs. Otherwise file is taken from %args.
name
open_dbs
%args
Calls instantiate_db
Close the DB with the key $name
$name
Fetch the db specified by $name if it is already open.
Registers the DB as open.
Instantiates a new database handle.
file is a required argument.
If class is not provided, the "db_class" will be used in place.
class
If txn is not provided and the env has transactions enabled, the current transaction if any is used. See txn_do
txn
txn_do
flags and properties can be overridden manually. If they are not provided build_db_flags and build_db_properties will be used.
flags
properties
build_db_flags
build_db_properties
Convenience wrappers for instantiate_db that set class.
Merges argument options into a flag integer.
Default arguments are taken from the dup and dupsort attrs.
Default arguments are taken from the autocommit and create attrs.
Executes the subroutine in an eval block. Calls txn_commit if the transaction was successful, or txn_rollback if it wasn't.
eval
txn_commit
txn_rollback
Transactions are kept on a stack internally.
Begin a new transaction.
If $parent_txn is provided the new transaction will be a child transaction.
$parent_txn
The new transaction is set as the active transaction for all registered database handles.
Commit a transaction.
Will die on error.
Rollback a transaction.
Associate secondary with primary, using callback to extract keys.
secondary
primary
callback
callback is invoked with the primary DB key and the value on every update to primary, and is expected to return a key (or with recent BerkeleyDB also an array reference of keys) with which to create indexed entries.
Fetching on secondary with a secondary key returns the value from primary.
Fetching with pb_get will also return the primary key.
pb_get
See the BDB documentation for more details.
Returns a list of all the registered databases.
This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.
darcs send
Yuval Kogman <nothingmuch@woobling.org>
Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Expected text after =item, not a bullet
To install BerkeleyDB::Manager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BerkeleyDB::Manager
CPAN shell
perl -MCPAN -e shell install BerkeleyDB::Manager
For more information on module installation, please visit the detailed CPAN module installation guide.