SlideShare una empresa de 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.

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar 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
 

Similar 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

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

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 del editor