</div>
<div class="slide">
-<pre>package MyApp::Schema::Result::Author;
+<pre>package Foo::Schema::Result::Author;
use strict; use warnings;
__PACKAGE__->table('authors');
__PACKAGE__->add_columns(
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many( books =>
- 'MyApp::Schema::Result::Book', 'author_id'
+ 'Foo::Schema::Result::Book', 'author_id'
);
1;
</pre>
</div>
<div class="slide">
-<pre>package MyApp::Schema::Result::Book;
+<pre>package Foo::Schema::Result::Book;
use strict; use warnings;
__PACKAGE__->table('books');
__PACKAGE__->add_columns(
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->belongs_to( author =>
- 'MyApp::Schema::Result::Author', 'author_id'
+ 'Foo::Schema::Result::Author', 'author_id'
);
1;
</pre>
</div>
<div class="slide">
- <p>too much typing! too much maintenance!</p>
- </div>
-
- <div class="slide">
<h1>Schema::Loader</h1>
- <pre>code for S::L here</pre>
- </div>
-
- <div class="slide">
- <h1>splitting logic cleanly</h1>
- <p>Foo::Schema::Result::Foo = an individual row</p>
- <p>Foo::Schema::ResultSet::Foo = searches / results</p>
- </div>
+ <p>DB -> Perl vs Perl -> DB</p>
+<pre>package Foo::Schema;
+use strict; use warnings;
+use base 'DBIx::Class::Schema::Loader';
+__PACKAGE__->loader_options({
+ naming => 'v7',
+ debug => $ENV{DBIC_TRACE},
+});
+1;
- <div class="slide">
- <h1>using your Schema</h1>
- <pre>example usage code goes here</pre>
- </div>
+# elsewhere...
- <div class="slide">
- <h1>DEBUGGING</h1>
- <pre>DBIC_TRACE=1 ./your_script.pl</pre>
+my $schema = Foo::Schema->connect($dsn, $user, $pass);
+</pre>
</div>
<div class="slide">
- <h1>Schema::Loader</h1>
-<pre>Foo::Schema::Result::Authors->table("authors");
-Foo::Schema::Result::Authors->add_columns(
- id => {
- data_type => "INT",
- default_value => undef,
- is_nullable => 0,
- size => 8
- },
- title => {
- data_type => "VARCHAR",
- default_value => undef,
- is_nullable => 1,
- size => 255,
- },
-);
-Foo::Schema::Result::Authors->set_primary_key("id");</pre>
+ <h1>Splitting Logic Cleanly</h1>
+ <p>Foo::Schema::Result::Bar = individual row</p>
+ <p>Foo::Schema::ResultSet::Bar = searches / table </p>
</div>
<div class="slide">
- <h1>Schema::Loader</h1>
-<pre>Foo::Schema::Result::Books->table("books");
-Foo::Schema::Result::Books->add_columns(
- id => {
- data_type => "INT",
- default_value => undef,
- is_nullable => 0,
- size => 8
- },
- name => {
- data_type => "VARCHAR",
- default_value => undef,
- is_nullable => 1,
- size => 255,
- },
- author => {
- data_type => "INT",
- default_value => undef,
- is_nullable => 1,
- size => 8
- },
-);
-Foo::Schema::Result::Books->set_primary_key("id");</pre>
+ <h1>Using your Schema</h1>
+<pre>#!perl
+use strict; use warnings;
+use lib 'lib';
+use Foo::Schema;
+my $schema = Foo::Schema->connect($dns, $user, $pass);
+my $author_rs = $schema->resultset('Author');
+my $author = $author_rs->create({
+ name => 'Douglas Adams',
+});
+my $book = $author->add_to_books({
+ title => '42',
+});
+</pre>
</div>
<div class="slide">
- <h1>Schema::Loader</h1>
-<pre>Foo::Schema::Result::Authors->has_many(books => "Foo::Schema::Books",
- { "foreign.author" => "self.id" });
-
-Foo::Schema::Result::Books->belongs_to(author => "Foo::Schema::Authors",
- { id => "author" });</pre>
+ <h1>DEBUGGING</h1>
+ <pre>DBIC_TRACE=1 ./your_script.pl</pre>
</div>
<div class="slide">
<div class="slide">
<h1>overloading</h1>
-<pre>Foo::Schema::Result::Books
-Foo::Schema::ResultSet::Books
-Foo::Schema::Result::Authors
-Foo::Schema::ResultSet::Books</pre>
+<pre>Foo::Schema::Result::Book
+Foo::Schema::ResultSet::Book
+Foo::Schema::Result::Author
+Foo::Schema::ResultSet::Book</pre>
</div>
<div class="slide">
<h1>Result::</h1>
-<pre>package Foo::Schema::Result::Books;
-use base 'DBIx::Class';
+<pre>package Foo::Schema::Result::Book;
+use base 'DBIx::Class::Core';
use strict;
use warnings;
+# Result code here
+
sub isbn {
my $self = shift;
<div class="slide">
<h1>Result:: (inflating)</h1>
-<pre>package Foo::Schema::Result::Books;
-use base 'DBIx::Class';
+<pre>package Foo::Schema::Result::Book;
+use base 'DBIx::Class::Core';
use strict;
use warnings;
+# Result code here
+
+__PACKAGE__->load_components('InflateColumn');
use DateTime::Format::MySQL;
__PACKAGE__-><strong>inflate_column</strong>(
<strong>date_published</strong> => {
inflate => sub { DateTime::Format::MySQL->parse_date(shift) },
deflate => sub { shift->ymd},
- }
-);
-# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
- </div>
-
- <div class="slide">
- <h1>Result:: (inflating)</h1>
-<pre>package Foo::Schema::Result::Books;
-use base 'DBIx::Class';
-use strict;
-use warnings;
-
-use DateTime::Format::MySQL;
-
-__PACKAGE__->inflate_column(
- date_published => {
- <strong>inflate => sub { DateTime::Format::MySQL->parse_date(shift) },
- deflate => sub { shift->ymd},</strong>
- }
+ },
);
-# Automatic see: DBIx::Class::InflateColumn::DateTime
-# Automatic see: DBIx::Class::InflateColumn::DateTime
# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
</div>
<div class="slide">
<h1>ResultSets::</h1>
-<pre>package Foo::Schema::<strong>ResultSet::Books</strong>;
-use base '<strong>DBIx::Class::ResultSet</strong>';
-sub the_ultimate_books {
- my $self = shift;
- <strong>return $self->search({ title => { -like => '%42%' } })</strong>
-}
-sub by_author {
- my ( $self, $author ) = @_;
- return $self->search({ author => $author->id })
-}
-
-1;</pre>
- </div>
-
- <div class="slide">
- <h1>ResultSets::</h1>
-<pre>package Foo::Schema::ResultSet::Books;
-use base 'DBIx::Class::ResultSet';
-sub the_ultimate_books {
- my $self = shift;
- return $self->search({ title => { -like => '%42%' } });
-}
-sub by_author {
- my ( $self, $author ) = @_;
- <strong>return $self->search({ author => $author->id })</strong>
-}
-
-1;</pre>
- </div>
-
- <div class="slide">
- <h1>ResultSets::</h1>
<pre>use Foo::Schema;
-my $book_model = Foo::Schema->resultset('Books');
-my $book_rs = $book_model->the_ultimate_books;
-my @books = $book_rs->all;</pre>
+my $schema = Foo::Schema->connect(...);
+my $book_rs = Foo::Schema->resultset('Book');
+my $book_search = $book_rs->the_ultimate_books;
+my @books = $book_search->all;</pre>
</div>
<div class="slide">
- <h1>ResultSets::chaining</h1>
-<pre>use Foo::Schema;
-my $book_model = Foo::Schema->resultset('Books');
-my $author_model = Foo::Schema->resultset('Authors');
+ <h1>ResultSets: Chaining</h1>
+<pre>
+my $book_rs = $schema->resultset('Book');
+my $author_rs = $schema->resultset('Author');
my $author = $author_model->search({ name => 'Douglas Adams' })->single;
my $book_rs = $book_model->the_ultimate_books->by_author($author);
my @books = $book_rs->all;</pre>
</div>
<div class="slide">
- <h1>ResultSets::chaining</h1>
-<pre>my $book_rs = $book_model
+ <h1>ResultSets: Chaining</h1>
+<pre>$book_rs = $schema->resultset('Book')
->the_ultimate_books
->by_author($author);</pre>
or
-<pre>my $book_rs = $book_model
- ->the_ultimate_books();
+<pre>my $book_rs = $schema->resultset('Book')
+ ->the_ultimate_books;
$book_rs = $book_rs->by_author($author);</pre>
<pre># Debug (SQL):
<div class="slide">
<h1>overloading before new record</h1>
- </div>
-
- <div class="slide">
- <h1>overloading before new record</h1>
- <pre>package Foo::Schema::Result::Authors;
-use base 'DBIx::Class';
+ <pre>package Foo::Schema::Result::Author;
+use base 'DBIx::Class::Core';
sub new {
my ( $class, $attrs ) = @_;
<div class="slide">
<h1>many_to_many</h1>
- <pre>package Foo::Schema::<strong>Result::Books</strong>;
-use base 'DBIx::Class';
+ <pre>package Foo::Schema::<strong>Result::Book</strong>;
+use base 'DBIx::Class::Core';
__PACKAGE__->many_to_many(
authors => "author_and_books", 'author'
<div class="slide">
<h1>many_to_many</h1>
- <pre>package Foo::Schema::<strong>Result::Books</strong>;
-use base 'DBIx::Class';
+ <pre>package Foo::Schema::<strong>Result::Book</strong>;
+use base 'DBIx::Class::Core';
__PACKAGE__->many_to_many(
authors <strong># Accessor name</strong>
<div class="slide">
<h1>many_to_many</h1>
- <pre>package Foo::Schema::Result::Authors;
-use base 'DBIx::Class';
+ <pre>package Foo::Schema::Result::Author;
+use base 'DBIx::Class::Core';
__PACKAGE__->many_to_many(
"books" <strong># Accessor Name</strong>