SlideShare uma empresa Scribd logo
1 de 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.

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Curscatalyst
CurscatalystCurscatalyst
CurscatalystKar Juan
 
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
 

Semelhante a 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
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
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
 

Último

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 

Último (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 

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.

Notas do Editor