3 ms·
Just another reason to use object databases: role Person { has qw/age height weight serial_number/ } class Man with Person { has 'length' } class Woma
by jrockway 17y ago
Just another reason to use object databases:
role Person { has qw/age height weight serial_number/ }
class Man with Person { has 'length' }
class Woman with Person { has 'size' }
class ... # whatever else people can be
# assume index on "does Person" set
my $bob = $db->get_person('Bob'); # isa Man
my $harry = $db->get_person('Harry'); # isa Man
my $sally = $db->get_person('Sally'); # isa Woman
# i think there was a movie about this
txn_do {
my $m = Marriage->new( people => [$harry, $sally] );
$harry->add_marriage( $m ); # in real life, there is a trigger on $m->add_person that does this
$sally->add_marriage( $m );
$db->store_marriage( $m ); # harry and sally are stored too
};
# didn't work out.
$m->annul( on => DateTime->now );
$db->store( $m );
$harry->is_married; # false
$harry->has_been_married; # true
$m2 = Marriage->new( people => [$bob, $harry] );
...
$harry->is_married; # returns $m2
my $tom = $db->get_person('Tom');
$m2->add_person( $tom ); # "three way"
...
Anyway, object graphs make modeling all the possibilities pretty easy; with the right indexes (on people and marriages) it's fast, with the right data structures it's lossless (annul pushes the marriage onto a history for that person), and with the right triggers (adding a person to a marriage adds a marriage to the person) the data stays consistent.
- Semiapies 17y agoAs I reread this, I hoped someone would try to take this out of the relational paradigm. :)