DBIx::TableHash 1.05 review
DownloadDBIx::TableHash is a Perl module that can tie a hash to a mysql table + SQL utils. SYNOPSIS use DBIx::TableHash; my $D
|
|
DBIx::TableHash is a Perl module that can tie a hash to a mysql table + SQL utils.
SYNOPSIS
use DBIx::TableHash;
my $DBHash = DBIx::TableHash->create_or_die
(my $Params =
{
DBIDriver => 'mysql',
Database => 'mydatabase',
HostName => 'localhost',
Port => undef,
Login => '',
Password => '',
TableName => 'SalesPeople',
KeyField => 'FullName',
## For multi-key lookup:
FixedKeys => {AreaCode => 415,
StatusCode => 'Active',
RecordType => 'Primary'},
## To retrieve a single value:
ValueField => 'PhoneNumber',
## ... or for "multi-value" retrieval...
ValueField => undef,
## ... optionally specifying...
RetrieveFields => [qw(Title Territory Quota)],
## For caching:
CacheMode => 'CacheBeforeIterate'
## or...
CacheMode => 'CacheOneTime'
## or...
CacheMode => 'CacheNone'
}
);
my %DBHash; tie(%DBHash, 'DBIx::TableHash', $Params);
my $DBHash = DBIx::TableHash->create($Params) or die "Help!";
my $DBHash = DBIx::TableHash->create_or_die($Params);
my $DBHash = DBIx::TableHash->create_copy($Params) or die "Help!";
my $DBHash = DBIx::TableHash->create_copy_or_die($Params);
All parameters are passed via a single anonymous hash.
All parameters are optional, but you'll almost always need to specify Database, TableName, and KeyField.
Omitting ValueField puts the hash in "multi-value" mode, where you store/retrieve a hash of fields/values instead of a single value. In "multi-value" mode all fields in each record are retrieved on every fetch; RetrieveFields limits fields retrieved to a specified list.
Specifying FixedKeys puts the hash in "multi-key" mode, in which only a subset of the database table, corresopnding to records that match the spec in FixedKeys, is operated on.
Cache modes reduce querying, but lose synchronization and hog memory.
The object is designed to be easy subclass. Try making a subclass that sets defaults for all or most of the parameters, so the caller doesn't have to supply any at instantiation time.
"create_copy" methods efficiently create and return potentially huge untied hash "snapshot" of the same data that would have been retrieved by the corresponding tied hash.
Requirements:
Perl
DBIx::TableHash 1.05 search tags