NAME
DBIx::Inline::ResultSet - Methods for searching and altering tables
fetch
Fetches the results for the entire resulset
count
Returns the number of rows found
all
Returns all rows in a table as a resultset
my $rs = $schema->resultset('Users')->all;
first
Get the first result from a resultset
last
Get the last result from a resultset
next
A simple iterator to loop through a resultset. Each returned result will be returned as a Result.
while(my $row = $result->next) {
print $row->{name};
}
primary_key
Sets the primary key for the current ResultSet
$rs->primary_key('id');
search
Access to the SQL SELECT query. Returns an array with the selected rows, which contains a hashref of values. First parameter is an array of what you want returned ie: SELECT this, that If you enter an empty array ([]), then it will return everything ie: SELECT * The second parameter is a hash of keys and values of what to search for.
my $res = $resultset->search([qw/name id status/], { status => 'active' });
my $res = $resultset->search([], { status => 'disabled' });
my $res = $resultset->search([], { -or => [ name => 'Test', name => 'Foo' ], status => 'active' });
my $res = $resultset->search([],
{ status => 'active' },
{
order => ['id'],
rows => 10,
}
);
insert
Inserts a new record.
my $user = $resultset->insert({name => 'Foo', user => 'foo_bar', pass => 'baz'});
$user->load_accessors;
print $user->name . "\n";
print "Last inserted primary key: " . $resultset->insert_id . "\n";
update
Updates the current result using the hash specified
my $res = $dbh->resultset('foo_table')->search([], { id => 5132 });
if ($res->update({name => 'New Name'})) {
print "Updated!\n";
}
insert_id
Gets the primary key value of the last inserted row. It will require the primary key to be set, though
delete
Drops the records in the current search result
my $res = $resultset->search([], { id => 2 });
$res->delete; # gone!
method
Creates a ResultSet method on the fly. Use it to create accessors, or shortcuts
$rs->method(is_active => sub {
return shift->search([], { account_status => 'active' });
});
print "Rows: " . $rs->is_active->count . "\n";
search_join
Performs a SQL JOIN to fetch "related" records. Say you want to find what books belong to what author. We want to find books matching author ID 2.
my $authors = $dbi->model('Authors')->table('authors');
$authors->search_join([], { authors => 'books', on => [ qw(id author_id) ] }, { id => 2 });