<div class="slide">
<h1>->deploy</h1>
<p>Perl -> DB</p>
-<pre>my $schema = Foo::Schema->connect($dsn, $user, $pass);
+<pre>my $schema = Foo::Schema->connect(
+ $dsn, $user, $pass
+);
$schema->deploy
</pre>
<p>See also: <a href="http://search.cpan.org/perldoc?DBIx::Class::DeploymentHandler">DBIx::Class::DeploymentHandler</a></p>
# elsewhere...
-my $schema = Foo::Schema->connect($dsn, $user, $pass);
+my $schema = Foo::Schema->connect(
+ $dsn, $user, $pass
+);
</pre>
</div>
<p>Made for inserting lots of rows very quicky into database</p>
<pre>$schema->populate([ Users =>
[qw( username password )],
- [qw( frew >=4char$ )],
+ [qw( frew >=4char$ )],
[qw( ... )],
[qw( ... )],
);
address => {
street => '123 Turtle Back Lane',
state => { abbreviation => 'ME' },
- city => { name => 'Lowell' },
+ city => { name => 'Lowell' },
},
});
</pre>
<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>
+ <li>DBIC::Helper::ResultSet::IgnoreWantarray</li>
+ <li>DBIC::Helper::ResultSet::Random</li>
+ <li>DBIC::Helper::ResultSet::SetOperations</li>
+ <li>DBIC::Helper::Row::JoinTable</li>
+ <li>DBIC::Helper::Row::NumifyGet</li>
+ <li>DBIC::Helper::Row::SubClass</li>
+ <li>DBIC::Helper::Row::ToJSON</li>
</ul>
</div>
</div>
<div class="slide">
- <h1>Extensible: DBIx::Class::Schema::KiokuDB</h1>
+ <h1>Extensible: Kioku</h1>
<ul class="incremental">
+ <li>DBIx::Class::Schema::KiokuDB</li>
<li>Kioku is the new hotness</li>
<li>Mix RDBMS with Object DB</li>
<li>beta ( == sexy )</li>
<pre>package MyApp::Schema::ResultSet::Book;
use base 'DBIx::Class::ResultSet';
sub good {
- $_[0]->search({
- rating => { '>=' => 4 },
+ my $self = shift;
+ $self->search({
+ $self->current_source_alias .
+ '.rating' => { '>=' => 4 },
})
};
sub cheap {
- $_[0]->search({
- price => { '<=' => 5}
+ my $self = shift;
+ $self->search({
+ $self->current_source_alias .
+ '.price' => { '<=' => 5}
})
};
# ...
1;
</pre>
+ </div>
+
+ <div class="slide">
+ <h1>ResultSet method notes</h1>
<ul class="incremental">
<li>All searches should be ResultSet methods</li>
<li>Name has obvious meaning</li>
+ <li>current_source_alias helps things to work no matter what</li>
</ul>
</div>
<div class="slide">
<h1>search_related</h1>
-<pre>my @test_rs = ($schema->resultset('User')->search({'me.userid' => 'marial'})
+<pre>my $score = $schema->resultset('User')
+ ->search({'me.userid' => 'frew'})
->related_resultset('access')
->related_resultset('mgmt')
- ->related_resultset('orders')->search({'orders.reporttype' => 0})
- ->related_resultset('shops')->search({'shops.status' => 'Completed', 'shops.datecompleted' => {-between => ['2009-10-01','2009-10-08']}})
- ->related_resultset('rpt_score')->get_column('raw_scores')->first);
+ ->related_resultset('orders')
+ ->telephone
+ ->search_related( shops => {
+ 'shops.datecompleted' => {
+ -between => ['2009-10-01','2009-10-08']
+ }
+ })->completed
+ ->related_resultset('rpt_score')
+ ->get_column('raw_scores')
+ ->first;
</pre>
</div>
<div class="slide">
- <h1>related_resultset</h1>
-<pre>my @screens = $user->roles
- ->related_resultset('role_permissions')
- ->related_resultset('permission')
- ->related_resultset('permission_screens')
- ->related_resultset('screen')
- ->search(undef, { distinct => 1 })->all;</pre>
- </div>
-
- <div class="slide">
<h1>bonus rel methods</h1>
<pre>my $book = $author->create_related(
- <strong>books</strong> => {
- title => 'Another Discworld book',
-});
+ <strong>books</strong> => {
+ title => 'Another Discworld book',
+ }
+);
my $book2 = $pratchett->add_to_<strong>books</strong>({
title => 'MOAR Discworld book',
<h1>InflateColumn</h1>
<pre>package Foo::Schema::Result::Book;
use base 'DBIx::Class::Core';
+use DateTime::Format::MySQL;
# 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},
+ inflate => sub {
+ DateTime::Format::MySQL->parse_date(
+ shift
+ )
+ },
+ deflate => sub { shift->ymd },
},
);
-# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
+# Automatic see: DBIC::InflateColumn::DateTime</pre>
</div>
<div class="slide">
<div class="slide">
<h1>InflateColumn: inflation</h1>
-<pre>my $date_published = $book->date_published;
-print $date_published->month_abbr;</pre>
+<pre>say $book->date_published->month_abbr;</pre>
<strong><em>Nov</em></strong>
</div>
sub to_metric { $_[1] * .305 }
sub to_imperial { $_[1] * 3.28 }
-# Automatic see: DBIx::Class::InflateColumn::DateTime</pre>
</div>
<div class="slide">
<h1>ResultSetColumn</h1>
-<pre>my $rsc = $schema->resultset('Book')->get_column('price');
+<pre>my $rsc = $schema->resultset('Book')
+ ->get_column('price');
$rsc->min;
$rsc->max;
$rsc->sum;
<div class="slide">
<h1>Aggregates</h1>
<pre>my @res = $rs->search({}, {
- select => [qw(price genre), { max => price }, { avg => price }],
- as => [qw(price genre max_price avg_price)],
+ select => [
+ 'price',
+ 'genre',
+ { max => price },
+ { avg => price },
+ ],
+ as => [
+ qw(price genre max_price avg_price)
+ ],
group_by => [qw(price genre)],
});
for (@res) {
say $_->get_column('max_price');
say $_->get_column('min_price');
}</pre>
+ </div>
+
+ <div class="slide">
+ <h1>Aggregates Notes</h1>
<ul class="incremental">
<li>Careful, get_column can basicaly mean THREE things</li>
<li>private for get what you should use an accessor for</li>
<div class="slide">
<h1>HRI</h1>
<pre>$rs->search({}, {
- result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ result_class =>
+ 'DBIx::Class::ResultClass::HashRefInflator',
});</pre>
<ul class="incremental">
<li>Easy on memory</li>
<div class="slide">
<h1>Subquery Support</h1>
-<pre> my $inside_rs = $schema->resultset('Artist')->search({
+<pre>my $inside_query = $schema->resultset('Artist')
+ ->search({
name => [ 'Billy Joel', 'Brittany Spears' ],
-});
+})->get_column('id')->as_query;
my $rs = $schema->resultset('CD')->search({
- artist_id => { -in => $inside_rs->get_column('id')->as_query },
+ artist_id => { -in => $inside_query },
});</pre>
</div>
<div class="slide">
<h1>Bare SQL w/ Placeholders</h1>
<pre>$rs->update({
- price => \"price + $inc", # !!! SQL INJECTION VECTOR
+ # !!! SQL INJECTION VECTOR
+ price => \"price + $inc",
});
$rs->update({