2. About D::OD
• Author: Benjamin Trott
• Recently Version: 0.06
• Simple, transparent data interface, with
caching.
• Based on MT::ObjectDriver in MT.
Now MT included D::OD.
3. D::OD features
• Built-in supportRAM and Apache inPartitioning.
Support Memcached,
Caching and
caching.
• Have to support master-slaver_handle()/rw_handle().
Can change process for read/write using
structure in mind.
• Implementation is becauseso less model feature.
But implement by myself,
thin, east-to-use.
of
Has ‘has_a’ but not has ‘has_many’.
4. Class structures
• Driver definition about how to connection to
Class for
class
db and cache server, and partitioning rules.
• Object classwhat you call.
The model class
Class for definition about how to treat data on tables.
5. Class structures
• Other classes
- D::OD::ResultSet
In the middle of an implementation?
Do not use in MT.
- D::OD::Profiler
Simple profiler.
- D::OD::GearmanDBI
I do not know how to use;)
6. Simple usase
• Make object class for table
Make sub-class of D::OD::BaseObject,
and set table information using install_properties().
‘driver’ is D::OD::Driver::DBI.
7. Simple usage
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );
__PACKAGE__->install_properties(
datasource => 'artist',
columns => [ qw( id name orig_name band_id ) ],
primary_key => 'id',
driver => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ),
);
1;
8. CRUD and etc
• Create
my artist = Artist->new(
name => ' ',
fullname => ' II '
);
$artist->save;
# or
Artist->bulk_insert( [col1, col2], [ [d1, d2], [d1, d2] ]);
9. CRUD and etc
• Read
my $artist = Artist->lookup(1);
print $artist->name;
# or
$artist_iter = Artist->search( { name => ' ' } );
@artists = Artist->search( { name => ' ' );
# or
$artists_ref = Artist->lookup_multi( [ 1, 2, 3 ] );
16. Master-Slave structure
• Only override r_handle().in read process,
r_handle() is method that execute
so this method is used to connect to slave database.
22. Partitioning
# cont.
sub find_partition {
my ( $terms, $args ) = @_;
my $artist = Artist->lookup( $terms->{ artist_id } );
return ReplDriver->new(
%{ $artist->partition_obj->master },
slaves => $artist->partition_obj->slaves,
pk_generator => &pk_generator,
);
}
sub pk_generator {
my $obj = shift;
$obj->id( generate_id() );
1;
},
1;
23. Partitioning
my $cd = CD->new(
artist_id => 1,
title => ' '
);
$cd->save;
lookup() is depends on PartitionDriver implementation in partitioning.
24. At the end, I wish...
• Built-in support pager using Data::Page.
• Wants count() and more useful methods.
• Hard to execute simple SQL.
(Just do using D::OD::SQL?)
• And hard to execute ‘JOIN’.