
Metadata::DB

This is just like Metadata::Base, only we store in a database. An instance of this object represents a metadata record.


use Metadata::DB; my $dbh; my $o = new Metadata::DB($dbh); $o->load; $o->set( name => 'jack' ); $o->set( age => 14 ); $o->id(4); $o->save; use Metadata::DB; my $dbh; my $o = new Metadata::DB($dbh); $o->id(4); $o->load; $o->get( 'name' ); $o->set( 'age' );
If you pass the id to the constructor, it will attempt to load from db.
my $o = new Metadata::DB({ DBH => $dbh, id => 'james' });
You can directly tell it what the id will be , and then request to load.
my $o = new Metadata::DB({ DBH => $dbh });
$o->id('james');
$o->load;
my $o = new Metadata::DB({ DBH => $dbh });
$o->id('james');
$o->load; # you must call load
$o->id_exists;

Inherits Metadata::Base and all its methods.
argument is hash ref with at least a DBH argument, which is a database handle.
my $o = new Metadata::DB::Object({ DBH = $dbh });
Optional argument is 'id'.
perl setget method arg is number
returns boolean if the id is in the database
returns number of entries for this id
Works like set(), only you can provide many entries.
$o->add(
name => 'this',
age => 4,
);
save to db
will attempt to load from db YOU MUST CALL load() to check what is in the database
returns boolean if load() was triggered or called or not
returns hashref with all meta will attempt to load from db

WARNING Calling save() before load() will delete all record metadata previously saved.
delete ALL metadata with id 5 and save only 'name marc'.
my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->set( name=> 'marc' );
$m->save;
After, this will NOT load the metadata 'name marc':
my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->get( 'name' );
This example WILL load the metadata:
my $m3= Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->load;
$m->get( 'name' );
This example will NOT delete metadata and will add instead:
my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->load;
$m->set( age => 25 );
$m->save;
Why? Why not just override get and get all to take care of this? Wny not just call load() automatically?? Because that's up to you. You MAY want to NOT do this cpu intensive operation. Maybe you want to insert a million entries really quickly, thus you dont want to load every time, maybe you already know there is nothing in there.


Leo Charre