<div class="slide">
<h1>Authors</h1>
<h4>Originally Leo Lapworth @ LPW 2009</h4>
- <h4>Matthew S. Trout</h4>
+ <h4>Amiri Barksdale</h4>
<h4>Justin D. Hunter</h4>
<h4>Arthur Axel "fREW" Schmidt</h4>
</div>
<h1>What's up guys?</h1>
<div class="notes">
<ul>
- <li>How many people have designed a database with Foreign Keys?</li>
<li>How many people have used any ORM?<ul>
<li>In Perl?<ul>
<li>DBIC?</li>
- <li> Class::DBI? </li>
- <li> Rose::DB? </li>
- <li> Fey? </li>
- <li> Others? </li>
+ <li>Class::DBI?</li>
+ <li>Rose::DB?</li>
+ <li>Fey?</li>
+ <li>Others?</li>
</ul></li>
- <li>AR? </li>
- <li> DataMapper? </li>
+ <li>AR?</li>
+ <li>DataMapper?</li>
<li>(N)Hibernate?</li>
</ul></li>
</ul>
</div>
<div class="slide">
+ <h1>Purpose</h1>
+ <p>The purpose of this talk is to show you as many features of
+ DBIx::Class in 40 minutes so that when you need to do something with
+ it later you will know what's possible</p>
+ </div>
+
+ <div class="slide">
<h1>DBIx::Class?</h1>
<ul>
<li>ORM (object relational mapper)</li>
<li>SQL <-> OO (using objects instead of SQL)</li>
- <li>Simple, powerful, complex, fab and confusing</li>
<li>There are many ORMs, DBIx::Class just happens to be the best in Perl (personal opinion)</li>
</ul>
</div>
<div class="slide">
- <h1>Purpose</h1>
- <p>The purpose of this talk is to show you as many features of
- DBIx::Class in 40 minutes
- so that when you need to do something with it later you will
- know what's possible</p>
+ <h1>Meta</h1>
+ <p>These are reasons that are not technical or inherent to
+ the code of DBIC, but are totally awesome things about it.</p>
+ </div>
+
+ <div class="slide">
+ <h1>Large Community</h1>
+ <p>Currently there are 88 people listed as contributors to DBIC. That
+ ranges from documentation help, to test help, to added features,
+ to entire database support.</p>
+ </div>
+
+ <div class="slide">
+ <h1>Active Community</h1>
+ <p>Currently (June 9, 2010) 6 active branches (commited to in the last two weeks) in git. Last release (0.08122) had 14 new features, and 16 bug fixes. Of course that <a href="http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=blob;f=Changes">ebbs and flows</a>.</p>
+ </div>
+
+ <div class="slide">
+ <h1>Responsive Community</h1>
+ <ul class="incremental">
+ <li>needed MSSQL Order by support, they helped me add support</li>
+ <li>generally very welcoming of people willing to help</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>General ORM</h1>
+ <p>These are things that are in most other ORMs, but are still reasons
+ to use DBIC over raw SQL.</p>
+ </div>
+
+ <div class="slide">
+ <h1>Cross DB</h1>
+ <p>The vast majority of code should run on all databases without needing tweaking</p>
</div>
<div class="slide">
<h1>Basic CRUD</h1>
- <ul>
+ <ul class="incremental">
<li><strong>C</strong> - Create</li>
<li><strong>R</strong> - Read</li>
<li><strong>U</strong> - Update</li>
title => 'A book title',
author_id => $author_id,
});</pre>
- <p>Don't need to work to pair placeholders and values</p>
- </div>
-
- <div class="slide">
- <h1>DBIC: Create</h1>
-<pre>my $pratchett = $author_rs->create({
- name => 'Terry Pratchett',
-});</pre>
- </div>
-
- <div class="slide">
- <h1>DBIC: Create</h1>
-<pre>my $book = $pratchett->create_related(
- <strong>books</strong> => {
- title => 'Another Discworld book',
-});</pre>
-<strong>or</strong>
-<pre>my $book = $pratchett->add_to_<strong>books</strong>({
- title => 'Another Discworld book',
-});</pre>
- <p>Automaticaly fills in foreign key for you</p>
+ <ul class="incremental">
+ <li>No need to pair placeholders and values</li>
+ </ul>
</div>
<div class="slide">
my @books = $book_rs->search({
author => $author_id,
})->all;</pre>
- <p>TMTOWTDI</p>
+ <ul class="incremental">
+ <li>TMTOWTDI</li>
+ </ul>
</div>
<div class="slide">
</div>
<div class="slide">
- <h1>DBIC: Read</h1>
-<pre>my $resultset = $book_rs->search({
- author => $author_id,
-});</pre>
- <p>Search takes SQL::Abstract formatted queries</p>
- <pre>> perldoc SQL::Abstract</p>
- </div>
-
- <div class="slide">
<h1>SQL: Update</h1>
<pre>my $update = $dbh->prepare('
UPDATE books
</div>
<div class="slide">
- <h1>Creating models</h1>
+ <h1>OO Overidability</h1>
+ <ul class="incremental">
+ <li>Override new if you want to do validation</li>
+ <li>Override delete if you want to disable deletion</li>
+ <li>and on and on</li>
+ </ul>
+ <div class="notes">
+ <p>I got yelled at about this before by people, so
+ we don't get EVERYTHING from OO, but we do get a lot
+ so :-P</p>
+ </div>
</div>
<div class="slide">
-<pre>package Foo::Schema::Result::Author;
-__PACKAGE__->table('authors');
-__PACKAGE__->add_columns(
- id => {
- data_type => 'int',
- is_auto_increment => 1
- },
- title => {
- data_type => 'varchar',
- is_nullable => 1,
- size => 255,
- },
-);
-__PACKAGE__->set_primary_key('id');
-__PACKAGE__->has_many( books =>
- 'Foo::Schema::Result::Book', 'author_id'
-);
-1;
-</pre>
+ <h1>Convenience Methods</h1>
+ <ul class="incremental">
+ <li>find_or_create</li>
+ <li>create_or_update</li>
+ </ul>
</div>
<div class="slide">
-<pre style="float: left; font-size: 80%;">package Foo::Schema::Result::Book;
-use strict; use warnings;
-__PACKAGE__->table('books');
-__PACKAGE__->add_columns(
- id => {
- data_type => 'int',
- is_auto_increment => 1
- },
- name => {
- data_type => 'varchar',
- is_nullable => 1,
- size => 255,
- },
-</pre>
-<pre style="float: left; font-size: 80%;">
- author_id => {
- data_type => 'int',
- size => 8,
- },
-);
-__PACKAGE__->set_primary_key('id');
-__PACKAGE__->belongs_to( author =>
- 'Foo::Schema::Result::Author', 'author_id'
-);
-1;
-</pre>
+ <h1>Non-column methods</h1>
+ <p>Need a method to get a user's gravatar URL? Add a
+ gravatar_url method to their Result class</p>
+ </div>
+
+ <div class="slide">
+ <h1>RELATIONSHIPS</h1>
+ <ul class="incremental">
+ <li><a href="http://search.cpan.org/perldoc?DBIx::Class::Relationship#belongs_to">belongs_to</a></li>
+ <li><a href="http://search.cpan.org/perldoc?DBIx::Class::Relationship#has_many">has_many</a></li>
+ <li><a href="http://search.cpan.org/perldoc?DBIx::Class::Relationship#might_have">might_have</a></li>
+ <li><a href="http://search.cpan.org/perldoc?DBIx::Class::Relationship#has_one">has_one</a></li>
+ <li><a href="http://search.cpan.org/perldoc?DBIx::Class::Relationship#many_to_many">many_to_many</a> (technically not a relationship)</li>
+ <li>SET AND FORGET</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>DBIx::Class Specific Features</h1>
+ <p>These things may be in other ORM's, but they are very specific, so doubtful</p>
</div>
<div class="slide">
</div>
<div class="slide">
- <h1>Splitting Logic Cleanly</h1>
- <p>Foo::Schema::Result::Bar = individual row</p>
- <p>Foo::Schema::ResultSet::Bar = searches / table </p>
+ <h1>Populate</h1>
+ <p>Made for inserting lots of rows very quicky into database</p>
+<pre>$schema->populate([ Users =>
+ [qw( username password )],
+ [qw( frew >=4char$ )],
+ [qw( ... )],
+ [qw( ... )],
+);
+</pre>
+ <ul class="incremental">
+ <li>I use this to <a href="http://blog.afoolishmanifesto.com/archives/1255">export our whole (200M~) db to SQLite</a></li>
+ </ul>
</div>
<div class="slide">
- <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',
-});
+ <h1>Multicreate</h1>
+ <p>Create an object and all of it's related objects all at once</p>
+<pre>$schema->resultset('Author')->create({
+ name => 'Stephen King',
+ books => [{ title => 'The Dark Tower' }],
+ address => {
+ street => '123 Turtle Back Lane',
+ state => { abbreviation => 'ME' },
+ city => { name => 'Lowell' },
+ },
+</pre>
+ <div class="notes">
+ <ul>
+ <li>books is a has_many</li>
+ <li>address is a belongs_to which in turn belongs to state and city each</li>
+ <li>for this to work right state and city must mark abbreviation and name as unique</li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="slide">
+ <h1>Extensible</h1>
+ <p>DBIx::Class helped pioneer fast MI in Perl 5 with Class::C3, so it is made
+ to allow extensions to nearly every part of it.</p>
+ </div>
+
+ <div class="slide">
+ <h1>Extensible: DBIC::Helpers</h1>
+ <ul class="incremental">
+ <li>DBIx::Class::Helper::ResultSet::IgnoreWantarray</li>
+ <li>DBIx::Class::Helper::ResultSet::Random</li>
+ <li>DBIx::Class::Helper::ResultSet::SetOperations</li>
+ <li>DBIx::Class::Helper::Row::JoinTable</li>
+ <li>DBIx::Class::Helper::Row::NumifyGet</li>
+ <li>DBIx::Class::Helper::Row::SubClass</li>
+ <li>DBIx::Class::Helper::Row::ToJSON</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>Extensible: DBIC::TimeStamp</h1>
+ <ul class="incremental">
+ <li>Cross DB</li>
+ <li>set_on_create</li>
+ <li>set_on_update</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>Extensible: DBIx::Class::Schema::KiokuDB</h1>
+ <ul class="incremental">
+ <li>Kioku is the new hotness</li>
+ <li>Mix RDBMS with Object DB</li>
+ <li>beta ( == sexy )</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>SQL::Abstract</h1>
+ <pre>my $resultset = $book_rs->search({
+ name => { -like => "%$nick%" },
+ });</pre>
+ <ul class="incremental">
+ <li>(kinda) introspectible</li>
+ <li>Prettier than SQL</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>Result vs ResultSet</h1>
+ <ul class="incremental">
+ <li>Result == Row</li>
+ <li>ResultSet == Query</li>
+ <li>(less important but...)</li>
+ <li>ResultSource == Table</li>
+ <li>Storage == Database</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>ResultSet methods</h1>
+<pre>package MyApp::Schema::ResultSet::Book;
+use base 'DBIx::Class::ResultSet';
+sub good {
+ my $self = shift;
+ $self->search({
+ rating => { '>=' => 4 },
+ })
+};
+sub cheap {
+ my $self = shift;
+ $self->search({
+ price => { '<=' => 5}
+ })
+};
+# ...
+1;
+ </pre>
+ <ul class="incremental">
+ <li>All searches should be ResultSet methods</li>
+ <li>Name has obvious meaning</li>
+ </ul>
+ </div>
+
+ <div class="slide">
+ <h1>ResultSet method in Action</h1>
+ <pre>$schema->resultset('Book')->good</pre>
+ </div>
+
+ <div class="slide">
+ <h1>ResultSet Chaining</h1>
+<pre>$schema->resultset('Book')
+ ->good
+ ->cheap
+ ->recent
</pre>
</div>