Yote-SQLObjectStore
view release on metacpan or search on metacpan
describe.txt view on Meta::CPAN
imagine a great craigslist data tree, for storing useful things.
it is discoverable and does not need a secret handshake uuid.
my $staff = $store->fetch_path("/cl/staff/jim");
my $flag_report_prefs = $staff->fetch_path( "preferences/tools/flag_report" );
my $name = $staff->get_name;
my $columns = $flag_report_prefs->get_extra_columns;
$staff->set_quote( 'i love the list' );
$staff->rate_tool( 'flag_report', 4 );
$store->save; # saves all updates using a transaction
the getters and setters are automatically created. get_ and set_ are explicitly used
to reduce cognitive load and confusion. they are not mistaken for other methods.
it is easily defined
package cl::tree::staff;
use base 'cl::tree::obj';
our %cols = (
name => 'varchar(256)',
quote => 'varchar(1026)',
favorite_tools => '*ARRAY_*cl::tree:tool',
preferences => '*HASH<256>_*',
);
sub rate_tool {
my ($self, $tool, $rating) = @_;
my $tool = $self->store->fetch_path( "/cl/tools/$tool" );
$tool->apply_rating( $self, $rating );
}
1;
package cl::tree::tool;
our %cols = (
name => 'varchar(256)',
url => 'varchar(1026)',
about => 'text',
average_user_rating => 'float',
user_to_rating => '*HASH<256>_float',
);
sub apply_rating {
my ($self, $user, $rating) = @_;
my $userratings = $self->get_user_to_rating->tied_hash;
$userratings->{$user->get_name} = $rating;
my $total = 0;
my @vals = values %$userratings;
for my $rating (@vals) {
$total += $rating;
}
$self->set_average_user_rating( $total / @vals );
}
it is stored in sql, with versioned tables, and a script
automatically builds new versions of the tables and updates
old versions to the new. run the script, review the output
and then apply the output to update tables.
$ cl-tree-table-builder
( run in 0.737 second using v1.01-cache-2.11-cpan-5a3173703d6 )