DBIx-SQLEngine

 view release on metacpan or  search on metacpan

SQLEngine/Record/Extras.pm  view on Meta::CPAN

Fetch a single record based on its primary key.

=item visit_records

  @results = My::Students->visit_records( \&mysub, criteria=> ... );

Calls the provided subroutine on each matching record as it is retrieved. Returns the accumulated results of each subroutine call (in list context).

=item refetch_record

  $record->refetch_record();

Re-retrieve the values for this record from the database based on its primary key. 

=back

=cut

sub new { (shift)->new_with_values( @_ ) }

########################################################################

sub fetch_records { (shift)->fetch_select( @_ ) }
sub visit_records { (shift)->visit_select( @_ ) }
sub fetch_sql     { (shift)->fetch_select( sql => [ @_ ] ) }
sub fetch_id      { (shift)->select_record( @_ ) }

sub fetch {
  (shift)->fetch_select( 
	( ref $_[0] or ! defined $_[0] ) ? (where=>$_[0], order=>$_[1]) 
					: @_ 
  );
}

sub fetch_one {
  my $self = shift;
  my $records = $self->fetch( @_ );
  ( scalar @$records < 2 ) or
      carp "Multiple matches for fetch_one: " . join(', ', map "'$_'", @_ );
  
  $records->[0];
}

sub refetch_record {
  my $self = shift();
  my $db_row = $self->get_table()->select_row( $self )
    or confess;
  %$self = %$db_row;
  $self->post_fetch;
  $self;
}

########################################################################

sub change { (shift)->change_values() }

########################################################################

sub save_row   { (shift)->save_record(@_) }
sub insert_row { (shift)->insert_record( @_ ) }
sub update_row { (shift)->update_record( @_ ) }
sub delete_row { (shift)->delete_record( @_ ) }

########################################################################

1;



( run in 1.926 second using v1.01-cache-2.11-cpan-6736b670a1e )