S::L code
[dbsrgits/dbix-class-introduction-presentation.git] / slideshow.html
index f751727..ad49e67 100644 (file)
@@ -342,20 +342,72 @@ my @books = $book_model->search({
    </div>
 
    <div class="slide">
-      <pre>Example of a DBIC Result</pre>
-   </div>
-
-   <div class="slide">
-      <pre>Example of a DBIC Result</pre>
+<pre>package MyApp::Schema::Result::Author;
+use strict; use warnings;
+__PACKAGE__-&gt;table('authors');
+__PACKAGE__-&gt;add_columns(
+  id =&gt; {
+    data_type =&gt; 'int',
+    size      =&gt; 8,
+  },
+  title =&gt; {
+    data_type   =&gt; 'varchar',
+    is_nullable =&gt; 1,
+    size        =&gt; 255,
+  },
+);
+__PACKAGE__-&gt;set_primary_key('id');
+__PACKAGE__-&gt;has_many( books =&gt;
+   'MyApp::Schema::Result::Book', 'author_id'
+);
+1;
+</pre>
    </div>
 
    <div class="slide">
-      <p>too much typing!  too much maintenance!</p>
+<pre>package MyApp::Schema::Result::Book;
+use strict; use warnings;
+__PACKAGE__-&gt;table('books');
+__PACKAGE__-&gt;add_columns(
+  id =&gt; {
+    data_type =&gt; 'int',
+    size      =&gt; 8,
+  },
+  name =&gt; {
+    data_type   =&gt; 'varchar',
+    is_nullable =&gt; 1,
+    size        =&gt; 255,
+  },
+  author_id =&gt; {
+    data_type   =&gt; 'int',
+    size        =&gt; 8,
+    is_nullable =&gt; 1, # &lt;-- probably should be 0
+  },
+);
+__PACKAGE__-&gt;set_primary_key('id');
+__PACKAGE__-&gt;belongs_to( author =&gt;
+   'MyApp::Schema::Result::Author', 'author_id'
+);
+1;
+</pre>
    </div>
 
    <div class="slide">
       <h1>Schema::Loader</h1>
-      <pre>code for S::L here</pre>
+      <p>DB -&gt; Perl vs Perl -&gt; DB</p>
+<pre>package MyApp::Schema;
+use strict; use warnings;
+use base 'DBIx::Class::Schema::Loader';
+__PACKAGE__-&gt;loader_options({
+   naming =&gt; 'v7',
+   debug  =&gt; $ENV{DBIC_TRACE},
+});
+1;
+
+# elsewhere...
+
+my $schema = MyApp::Schema-&gt;connect($dsn, $user, $pass);
+</pre>
    </div>
 
    <div class="slide">