[Dbix-class] Ok, let's begin

Matt S Trout dbix-class at trout.me.uk
Tue Sep 20 21:36:35 CEST 2005


On Tue, Sep 20, 2005 at 10:46:28PM +0200, Krzysztof Krzyzaniak wrote:
> Simple Catalyst app. I have now loaded table in model:
> 
> package TrackCD::M::DBIC;
> 
> use strict;
> use base qw/DBIx::Class/;
> 
> __PACKAGE__->load_components(qw/Core DB PK::Auto::Pg Table Row 
> Relationship/);
> __PACKAGE__->connection
> (
>     TrackCD->config->{'dsn'},
>     TrackCD->config->{'username'},
>     TrackCD->config->{'password'} ,
>     { RaiseError => 1, PrintError => 0, ShowErrorStatement => 1, 
> TraceLevel => 0 }
> );
> 
> then in TrackCD::M::DBIC::Record;
> 
> use strict;
> use base qw/TrackCD::M::DBIC/;
> 
> 
> __PACKAGE__->table('record');
> __PACKAGE__->set_primary_key('rec_id');
> __PACKAGE__->add_relationship
> (
>     'tracks' => 'TrackCD::M::DBIC::Track',
>     {'foreign.rec_id' => 'self.rec_id'}
> );
> 
> 
> now in controller I am getting data:
> 
> my $records = TrackCD::M::DBIC::Record->search
> (
>                 {},
>                 {
>                 'order_by' => $orders{$order},
>                 'rows' => 50,
>                 'page' => 1
>                 }
> );
> 
> and finally I have
> 
> DBIx::Class::ResultSet and DBIx::Class::ResultSet->pager. In which way I 
> can use it? (I mean maybe there is some iterator class in ResultSet?)

ResultSet *is* an iterator.

$rs->next will return an object
$rs->all will return all objects in the resultset
$rs->reset does what you expect
$rs->count will count rows (via COUNT(*) without fetching data)
$rs->delete deletes all records in the resultset

-- 
     Matt S Trout       Specialists in perl consulting, web development, and
  Technical Director    UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list