SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Data::ObjectDriver
        id:clouder
     Yokohama.pm #5
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.
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’.
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.
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;)
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.
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;
CRUD and etc
• Create
my artist = Artist->new(
  name => '                   ',
   fullname => '                         II   '
);
$artist->save;
# or
Artist->bulk_insert( [col1, col2], [ [d1, d2], [d1, d2] ]);
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 ] );
CRUD and etc
• Update
 $artist->name( '   ' );
 $artist->save;
CRUD and etc
• Delete

 $artist->remove;
CRUD and etc
• has_a()
 __PACKAGE__->has_a( {
     class => 'Band',
     column => 'band_id',
     cached => 1,
 } );
CRUD and etc
• add_trigger() post_load pre_search pre_insert
  pre_save post_save
   post_insert pre_update post_update pre_remove
   post_remove post_inflate

 __PACKAGE__->add_trigger(
    pre_insert => sub {
       my ( $obj, $orig_obj ) = @_;
       ...
    },
 );
Caching
• Only change driver
  If there is not cache,
  connect to db using D::OD::Driver::DBI.
Caching
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   ...
   driver => Data::ObjectDriver::Driver::Cache::Memcached->new(
       cache => Cache::Memcached->new( servers => @servers ),
       fallback => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ),
   ),
   ...
);

1;
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.
Master-Slave structure
 • Object class
package Artist;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   ...
   driver => Data::ObjectDriver::Driver::Cache::Memcached->new(
       cache => Cache::Memcached->new( servers => @servers ),
       fallback => ReplDriver->new( %DB_INFO, slaves => [ slave01, ... ] ),
   ),
   ...
);
Master-Slave structure
 • Driver class
package ReplDriver;
use strict;
use base qw( Data::ObjectDriver::Driver::DBI );

__PACKAGE__->mk_accessors( qw( slaves ) );

sub init {
  my $driver = shift;
  my %param = @_;
  $driver->slaves( delete $param{ slaves } );
  $driver->SUPER::init( %param );
  return $driver;
}

# cont.
Master-Slave structure
 • Driver class(cont.)
# cont.

sub r_handle {
  my $driver = shift;
  my $db = shift || 'main';
  for my $slave ( shuffle @{ $driver->slaves } ) {
     # connect to $slave
     my $dbh = DBI->connect( $slave->{DB_INFO} );
     $driver->dbd->init_dbh($dbh);
     return $dbh;
  }
  $driver->rw_handle($db);
}

1;
Partitioning
package CD;
use strict;
use base qw( Data::ObjectDriver::BaseObject );

__PACKAGE__->install_properties(
   datasource => 'cd',
   columns     => [ qw( artist_id id title ) ],
   primary_key => [ qw( artist_id id ) ],
   driver      => PartitionDriver->driver,
);

1;
Partitioning
package PartitionDriver;
use strict;

sub driver {
  my $fallback = Data::ObjectDriver::Driver::Partition->new(
     get_driver => &find_partition,
  );
  Data::ObjectDriver::Driver::Cache::Memcached->new(
     cache => Cache::Memcached->new( servers => @servers ),
     fallback => $fallback,
  ),
}

# cont.
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;
Partitioning

my $cd = CD->new(
  artist_id => 1,
  title => '      '
);
$cd->save;


lookup() is depends on PartitionDriver implementation in partitioning.
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’.
Fin.

Weitere ähnliche Inhalte

Was ist angesagt?

Puppet and the HashiCorp Suite
Puppet and the HashiCorp SuitePuppet and the HashiCorp Suite
Puppet and the HashiCorp SuiteBram Vogelaar
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015Fernando Hamasaki de Amorim
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesBram Vogelaar
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonApache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonMasahiro Nagano
 
Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8Yoshiki Kurihara
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby CoreHiroshi SHIBATA
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしHiroshi SHIBATA
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer Hiroshi SHIBATA
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stackBootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stackBram Vogelaar
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmsom_nangia
 

Was ist angesagt? (20)

Puppet and the HashiCorp Suite
Puppet and the HashiCorp SuitePuppet and the HashiCorp Suite
Puppet and the HashiCorp Suite
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-ThonApache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
Apache::LogFormat::Compiler YAPC::Asia 2013 Tokyo LT-Thon
 
D2
D2D2
D2
 
Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
mruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなしmruby で mackerel のプラグインを作るはなし
mruby で mackerel のプラグインを作るはなし
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Usecase examples of Packer
Usecase examples of Packer Usecase examples of Packer
Usecase examples of Packer
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stackBootstrap your Cloud Infrastructure using puppet and hashicorp stack
Bootstrap your Cloud Infrastructure using puppet and hashicorp stack
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 

Ähnlich wie About Data::ObjectDriver

DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちRyo Miyake
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic ComponentsMateusz Tymek
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail Laurent Dami
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objectswebhostingguy
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Serverhendrikvb
 
Api Design
Api DesignApi Design
Api Designsartak
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009jonswar
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosqlSimon Su
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterPerrin Harkins
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 

Ähnlich wie About Data::ObjectDriver (20)

DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
Terraform Cosmos DB
Terraform Cosmos DBTerraform Cosmos DB
Terraform Cosmos DB
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Server
 
Api Design
Api DesignApi Design
Api Design
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
CHI-YAPC-2009
CHI-YAPC-2009CHI-YAPC-2009
CHI-YAPC-2009
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Nko workshop - node js & nosql
Nko workshop - node js & nosqlNko workshop - node js & nosql
Nko workshop - node js & nosql
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 

Kürzlich hochgeladen

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Kürzlich hochgeladen (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

About Data::ObjectDriver

  • 1. Data::ObjectDriver id:clouder Yokohama.pm #5
  • 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 ] );
  • 10. CRUD and etc • Update $artist->name( ' ' ); $artist->save;
  • 11. CRUD and etc • Delete $artist->remove;
  • 12. CRUD and etc • has_a() __PACKAGE__->has_a( { class => 'Band', column => 'band_id', cached => 1, } );
  • 13. CRUD and etc • add_trigger() post_load pre_search pre_insert pre_save post_save post_insert pre_update post_update pre_remove post_remove post_inflate __PACKAGE__->add_trigger( pre_insert => sub { my ( $obj, $orig_obj ) = @_; ... }, );
  • 14. Caching • Only change driver If there is not cache, connect to db using D::OD::Driver::DBI.
  • 15. Caching package Artist; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( ... driver => Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => Data::ObjectDriver::Driver::DBI->new( %DB_INFO ), ), ... ); 1;
  • 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.
  • 17. Master-Slave structure • Object class package Artist; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( ... driver => Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => ReplDriver->new( %DB_INFO, slaves => [ slave01, ... ] ), ), ... );
  • 18. Master-Slave structure • Driver class package ReplDriver; use strict; use base qw( Data::ObjectDriver::Driver::DBI ); __PACKAGE__->mk_accessors( qw( slaves ) ); sub init { my $driver = shift; my %param = @_; $driver->slaves( delete $param{ slaves } ); $driver->SUPER::init( %param ); return $driver; } # cont.
  • 19. Master-Slave structure • Driver class(cont.) # cont. sub r_handle { my $driver = shift; my $db = shift || 'main'; for my $slave ( shuffle @{ $driver->slaves } ) { # connect to $slave my $dbh = DBI->connect( $slave->{DB_INFO} ); $driver->dbd->init_dbh($dbh); return $dbh; } $driver->rw_handle($db); } 1;
  • 20. Partitioning package CD; use strict; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties( datasource => 'cd', columns => [ qw( artist_id id title ) ], primary_key => [ qw( artist_id id ) ], driver => PartitionDriver->driver, ); 1;
  • 21. Partitioning package PartitionDriver; use strict; sub driver { my $fallback = Data::ObjectDriver::Driver::Partition->new( get_driver => &find_partition, ); Data::ObjectDriver::Driver::Cache::Memcached->new( cache => Cache::Memcached->new( servers => @servers ), fallback => $fallback, ), } # cont.
  • 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’.
  • 25. Fin.

Hinweis der Redaktion