Skip to content

Instantly share code, notes, and snippets.

@arodland
Created September 13, 2009 01:40
Show Gist options
  • Save arodland/186042 to your computer and use it in GitHub Desktop.
Save arodland/186042 to your computer and use it in GitHub Desktop.
my $books = $schema->resultset('Books'); # Knows how to find every book.
# Knows how to find books published in the 90s.
my $nineties_books = $schema->search({
published => { -between => [1990, 1999] }
});
# Knows how to find books published in the 90s that
# were awesome -- see how the state keeps getting added to?
my $awesome_nineties_books = $nineties_books->search({
awesome => 'yes'
});
# Knows how to find the top ten most awesome 90s books.
my $top10 = $awesome_nineties_books->search(
undef,
{ order_by => { -desc => "awesomeness" } }
)->slice(0, 9);
# *now* we actually do a DB query for the first time
my @top_ten_books = $top10->all;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment