SlideShare una empresa de Scribd logo
1 de 55
DBIx::Skinny

     Ryo Miyake - nekoya -
         (id:studio-m)
,. -‐'''''""¨
                                (.     _,,,... -        |
                              |i i|      }! }} / |
                               |l {      j} /,, //                        10   LT
                                 i|:! _         u {:}//
                               | u' } , _,!V, |
                           ´f _{ {, '                ,          55
                      /'         | | {´,) `/ |< i
               ,
                  | _
                          ) iL         u' | |
                                   ! ⊇ ' :} V:::::              5    LT
            /               7'T'' u' __ /:::::::/
                 /'´r -—          ‐   ´ '"´ :::: -
          / //          ¨´ /'            ::::: ´
    '/         :::::` - ___ ::::: /                         }
_      /:::::::::::::::::::::::::: ` -{:::...
•               nekoya

• id:studio-m
• http://twitter.com/nekoya
• http://wassr.jp/user/nekoya
•
DBIx::SKinny
    by nekokak
SQL




DBIx::Skinny::Manual::JA::Intro
• CPAN
• github
• http://github.com/nekokak/p5-dbix-skinny
DBI          ORM


•    SQL

•          Row
• MyApp::DB, MyApp::DB::Schema
•       Row                 DBIx::Skinny::Row

• MyApp::DB::Row::{Table}
rule                      inflate/deflate
inflate/deflate


install_inflate_rule '^.+_at$' => callback {
   inflate {
       my $value = shift;
       return $value;
   };
   deflate {
       my $value = shift;
       return $value;
   };
};
rule                      inflate/deflate
my $timezone = DateTime::TimeZone->new(name => 'Asia/Tokyo');
install_inflate_rule '^.+_at$' => callback {
   inflate {
       my $value = shift;
       my $dt = DateTime::Format::Strptime->new(
          pattern => '%Y-%m-%d %H:%M:%S',
          time_zone => $timezone,
       )->parse_datetime($value);
       return DateTime->from_object( object => $dt );
   };
   deflate {
       my $value = shift;
       return DateTime::Format::MySQL->format_datetime($value);
   };
};
trigger

trigger
trigger
install_table 'user' => schema {
   pk 'id';
   columns qw/id name mail created_at updated_at/;
   trigger pre_insert => sub {
       my ( $class, $args ) = @_;
       $args->{created_at} ||= DateTime->now;
   };
   trigger pre_update => sub {
       my ( $class, $args ) = @_;
       $args->{updated_at} ||= DateTime->now;
   };
};
• inflate/deflate
• trigger
    trigger

    created_at    pre_insert
common_trigger (ry
trigger
trigger                common_trigger

install_common_trigger pre_insert => sub {
   my ($self, $args) = @_;
   $args->{created_at} ||= DateTime->now;
};


•                          trigger
trigger

install_common_trigger pre_insert => sub {
   my ($self, $args, $table) = @_;
   my $columns = $self->schema->schema_info
->{$table}->{columns};
   $args->{created_at} ||= DateTime->now
       if grep {/^created_at$/} @$columns;
};

               trigger
nekokak        YAPC

• http://nekokak.org/presen/yapcasia2009-dbix-
  skinny/


github

• http://github.com/nekokak/p5-dbix-skinny/blob/
  master/lib/DBIx/Skinny/Manual/JA/
DBIx::Skinny::Schema::Loader
MyApp::DB::Schema      install_table



• pk columns DB
• http://github.com/nekoya/p5-dbix-skinny-schema-
  loader
: load_schema

package Your::DB::Schema;
use base qw/DBIx::Skinny::Schema::Loader/;

__PACKAGE__->load_schema;
: load_schema
package Your::DB::Schema;
use base qw/DBIx::Skinny::Schema::Loader/;

install_table books => schema {
   trigger pre_insert => sub {
       my ($class, $args) = @_;
       $args->{ name } = 'HOGE';
   }
};
__PACKAGE__->load_schema;

1;
: make_schema_at
publish_schema.pl
   use DBIx::Skinny::Schema::Loader
         qw/make_schema_at/;


   print make_schema_at(
        'Your::DB::Schema',                # Schema class
        { },                               # options
        [ 'dbi:SQLite:test.db', '', '' ]   # connect info
   );
: make_schema_at

$ perl publish_schema.pl > Your/DB/Schema.pm

• DBIC
• Skinny   Schema 1

•
make_schema_at

my $tmpl = << '...';
# custom template
install_utf8_columns qw/jpname title content/;
install_common_trigger pre_insert => sub {
   my ($self, $args) = @_;
   $args->{created_at} ||= DateTime->now;
};
...
make_schema_at

print make_schema_at(
     'Mock::DB::Schema',
     {
         before_template => $before,
     },
     [ 'dbi:SQLite:test.db', '', '' ]
);

 • after_template
table_template

 • install_table
 • TT         table, pk, columns

install_table [% table %] => schema {
     pk '[% pk %]';
     columns qw/[% columns %]/;
};
DBIx::Skinny::
InflateColumn::DateTime
DBIx::Skinny::InflateColumn::DateTime

• _at, _on            DateTime           inflate/deflate

• created_xx, updated_xx
    inspired
    DBIx::Class::InflateColumn::DateTime::Auto
    (hidek++)
    http://blog.hide-k.net/archives/2006/08/
    dbixclassauto_i.phpdbixclassauto_i.php
DBIx::Skinny::InflateColumn::DateTime

• MySQL
• timestamp            now()



• insert      select

• Perl
•                                 …
DBIx::Skinny::InflateColumn::DateTime
package Your::DB::Schema;
use DBIx::Skinny::Schema;
use DBIx::Skinny::InflateColumn::DateTime;

install_table table1 => {
   pk 'id';
   columns qw/id name created_at updated_at/;
};

install_table table2 => {
   pk 'id';
   columns qw/id name booked_on created_on updated_on/;
};
Ark::Plugin::Authentication::
    Store::DBIx::Skinny
Ark by typester

• Catalyst
• http://typester.stfuawsc.com/slides/yapsasia2009-
  ark/
•        Ark

• Ark + Skinny
package MyApp;
use Ark;
use MyApp::Models;

use_model 'MyApp::Models';

use_plugins qw{
  Session
  Session::State::Cookie
  Session::Store::Memory

     Authentication
     Authentication::Credential::Password
     Authentication::Store::DBIx::Skinny
};
config 'Plugin::Authentication::Store::DBIx::Skinny' => {
   model     => 'db',
   table    => 'members',
   user_field => 'name',
};




•                      DBIC

•
DBIx::Skinny::AR
DBIx::Skinny::AR

• Any::Moose
• ActiveRecord
• http://github.com/nekoya/p5-dbix-skinny-ar
DBIx::Skinny::AR


• Model
•                     DB
DBIx::Skinny::AR
DBIC

• Row          use base 'DBIx::Class'

• Model   DB

• DBIC
• pixis                      …
DBIx::Skinny::AR



  DBIx::Skinny (ry
DBIx::Skinny::AR
package MyApp::DB;
use DBIx::Skinny;

package MyApp::DB::Schema;
use DBIx::Skinny::Schema;

install_table books => schema {
   pk 'id';
   columns qw/id author_id title/
};
• MyApp::DB::Schema          MyApp/DB.pm
• MyApp::DB
   use DBIx::Skinny setup => {
      dsn => 'dbi:SQLite:test.db',
      username => '',
      password => '',
   };


   MyApp::DB->connect($conf->{ database });
DBIx::Skinny::AR
package MyApp::AR;
use Any::Moose;
extends 'DBIx::Skinny::AR';

__PACKAGE__->setup('MyApp::DB');

1;
package Mock::Book;
use Any::Moose;
extends 'Mock::AR';

use Carp;

has 'id' => (
   is => 'rw',
   isa => 'Undef | Int',
);

has 'author_id' => (
   is => 'rw',
   isa => 'Undef | Int',
);
has 'title' => (
   is     => 'rw',
   isa => 'Str',
   traits => [qw/Unique/],
);

__PACKAGE__->belongs_to('author');

1;
find
my $book = MyApp::Book->find(1);

my $book = MyApp::Book->find({ title => ‘hoge’ });

my $books = MyApp::Book->find_all;

my $latests = MyApp::Book->find_all(
   { author_id => $author_id },
   { order_by => { id => 'desc' } }
);
Relationships
• belongs_to
• has_one
• has_many
• many_to_many
Relationships
• $book->author
•
   has 'author' => (
      is    => 'ro',
      isa => 'MyApp::Author',
      clearer => 'clear_author',
      lazy => 1,
      default => sub { … }
   );
Relationships
DB

 • $book->author->clear_author
 • $book->author->reload
Trait::Unique
has 'title' => (
   is     => 'rw',
   isa => 'Str',
   traits => [qw/Unique/],
);


 •
 •
 •          SQL
• perldoc DBIx::Skinny

•
• SQLite

•
IRC

#dbix-skinny at perl.org ( irc.perl.org )

#perl-casual at Freenode ( irc.freenode.net )
Skinny   Skinny




              [eof]

Más contenido relacionado

La actualidad más candente

Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 

La actualidad más candente (20)

Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 
Redis
RedisRedis
Redis
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Word Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with TraceryWord Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with Tracery
 
Getting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot FrameworkGetting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot Framework
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019Let's write secure drupal code! - Drupal Camp Pannonia 2019
Let's write secure drupal code! - Drupal Camp Pannonia 2019
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Undercover Pods / WP Functions
Undercover Pods / WP FunctionsUndercover Pods / WP Functions
Undercover Pods / WP Functions
 
コードの動的生成のお話
コードの動的生成のお話コードの動的生成のお話
コードの動的生成のお話
 
Substitution Cipher
Substitution CipherSubstitution Cipher
Substitution Cipher
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019Let's write secure Drupal code! DUG Belgium - 08/08/2019
Let's write secure Drupal code! DUG Belgium - 08/08/2019
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 

Destacado (8)

アラートメールの運用
アラートメールの運用アラートメールの運用
アラートメールの運用
 
俺とプログラマーズカフェ
俺とプログラマーズカフェ俺とプログラマーズカフェ
俺とプログラマーズカフェ
 
About test
About testAbout test
About test
 
SmartCSS
SmartCSSSmartCSS
SmartCSS
 
Python setup
Python setupPython setup
Python setup
 
なぜパスワードを使い回すとシステム部が切れるのか
なぜパスワードを使い回すとシステム部が切れるのかなぜパスワードを使い回すとシステム部が切れるのか
なぜパスワードを使い回すとシステム部が切れるのか
 
オブジェクト指向プログラミング再入門
オブジェクト指向プログラミング再入門オブジェクト指向プログラミング再入門
オブジェクト指向プログラミング再入門
 
インターネット広告とPerl、ここ数年の歩み
インターネット広告とPerl、ここ数年の歩みインターネット広告とPerl、ここ数年の歩み
インターネット広告とPerl、ここ数年の歩み
 

Similar a DBIx::Skinnyと仲間たち

Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
Naoya Ito
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
Puppet
 

Similar a DBIx::Skinnyと仲間たち (20)

Mojo – Simple REST Server
Mojo – Simple REST ServerMojo – Simple REST Server
Mojo – Simple REST Server
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
テストデータどうしてますか?
テストデータどうしてますか?テストデータどうしてますか?
テストデータどうしてますか?
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
Perl object ?
Perl object ?Perl object ?
Perl object ?
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Bioinformatica p6-bioperl
Bioinformatica p6-bioperlBioinformatica p6-bioperl
Bioinformatica p6-bioperl
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekingeBioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekinge
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 

Último

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
Safe Software
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 

DBIx::Skinnyと仲間たち