From: Arthur Axel 'fREW' Schmidt Date: Fri, 28 May 2010 05:00:16 +0000 (-0500) Subject: more exmaples, less S::L X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e5edefe78c9604fe09f99be929dfab04eb5a6ba;p=dbsrgits%2Fdbix-class-introduction-presentation.git more exmaples, less S::L --- diff --git a/slideshow.html b/slideshow.html index ad49e67..3b7f5db 100644 --- a/slideshow.html +++ b/slideshow.html @@ -411,14 +411,26 @@ my $schema = MyApp::Schema->connect($dsn, $user, $pass);
-

splitting logic cleanly

-

Foo::Schema::Result::Foo = an individual row

-

Foo::Schema::ResultSet::Foo = searches / results

+

Splitting Logic Cleanly

+

MyApp::Schema::Result::Foo = individual row

+

MyApp::Schema::ResultSet::Foo = searches / table

-

using your Schema

-
example usage code goes here
+

Using your Schema

+
#!perl
+use strict; use warnings;
+use lib 'lib';
+use MyApp::Schema;
+my $schema = MyApp::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',
+});
+
@@ -427,61 +439,6 @@ my $schema = MyApp::Schema->connect($dsn, $user, $pass);
-

Schema::Loader

-
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");
-
- -
-

Schema::Loader

-
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");
-
- -
-

Schema::Loader

-
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" });
-
- -

SQL - debugging

INSERT INTO authors (name)
    VALUES (?): 'Douglas Adams'
@@ -492,10 +449,10 @@ INSERT INTO books (author, title)
 
    

overloading

-
Foo::Schema::Result::Books
-Foo::Schema::ResultSet::Books
-Foo::Schema::Result::Authors
-Foo::Schema::ResultSet::Books
+
MyApp::Schema::Result::Book
+MyApp::Schema::ResultSet::Book
+MyApp::Schema::Result::Author
+MyApp::Schema::ResultSet::Book
@@ -505,6 +462,8 @@ use base 'DBIx::Class'; use strict; use warnings; +# Result code here + sub isbn { my $self = shift;