DBIx::DBO2::Record - A row in a table in a datasource
package MyRecord; use DBIx::DBO2::Record '-isasubclass'; MyRecord->table( DBIx::DBO2::Table->new( name=>'foo', datasource=>$ds ) ); package main; my $results = MyRecord->fetch_all; foreach ( $results->records ) { }
The DBIx::DBO2::Record class represents database records in tables accessible via DBIx::SQLEngine.
By subclassing this package, you can easily create a class whose instances represent each of the rows in a SQL database table.
package My::Record; use DBIx::DBO2::Record '-isasubclass';
Allows for a simple declaration of inheritance.
Each Record class stores a reference to the table its instances are stored in.
RecordClass->table ( $table ) RecordClass->table () : $table
Establishes the table a specific class of record will be stored in.
RecordClass->count_rows () : $integer
Delegated to table.
RecordClass->datasource () : $datasource
Delegated to table. Returns the table's SQLEngine.
RecordClass->do_sql ( $sql_statement )
Delegated to datasource.
Record objects are constructed when they are fetched from their table as described in the next section, or you may create your own for new instances.
my $obj = MyRecord->new( method1 => value1, ... ); my $shallow_copy = $record->new;
Create a new instance. (Class::MakeMethods::Standard::Hash:new).
my $similar_record = $record->clone;
Makes a copy of a record and then clears its id so that it will be recognized as a distinct, new row in the database rather than overwriting the original when you save it.
Inheritable Hook. Subclasses should override this with any functions they wish performed immediately after each record is created and initialized.
$recordset = My::Students->fetch_records( criteria => {status=>'active'} );
Fetch all matching records and return them in a RecordSet.
$dave = My::Students->fetch_one( criteria => { name => 'Dave' } );
Fetch a single matching record.
$prisoner = My::Students->fetch_id( 6 );
Fetch a single record based on its primary key.
$record->refetch_record();
Re-retrieve the values for this record from the database based on its primary key.
Inheritable Hook. Subclasses should override this with any functions they wish performed immediately after each record is retrieved from the database.
After constructing a record, you may save any changes by calling insert_record.
$record->insert_record ()
Inheritable Hook. Subclasses should override this with any functions they wish performed before a row is written out to the database.
Inheritable Hook. Subclasses should override this with any functions they wish performed after a row is written out to the database.
After retrieving a record, you may save any changes by calling update_record.
$record->update_record ()
$record->delete_record () : $boolean_completed
Checks to see if pre_delete returns a false value. If not, asks the table to delete the row.
$record->pre_delete () : $boolean_is_ok
Subclasses may override this to provide validation or other behavior
$record->post_delete ()
Called after a record has been deleted from the datasource.
Wrappers for new/fetch and insert/update.
RecordClass->get_record ( $id_or_undef ) : $new_or_fetched_record_or_undef
Calls new if no ID is provided, or if the ID is the special string "-new"; otherwise calls fetch_id.
$record->save_record () : $boolean_completed
Determines whether the record has an id assigned to it and then calls either insert_record or update_record.
Simple interface for applying changes.
$record->call_methods( method1 => value1, ... );
Call provided method names with supplied values. (Class::MakeMethods::Standard::Universal:call_methods).
RecordClass->new_and_save ( %method_argument_pairs ) : $record
Calls call_methods, and then save_record.
$record->change_and_save ( %method_argument_pairs ) : $record
See DBIx::DBO2 for an overview of this framework.
To install DBIx::DBO2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::DBO2
CPAN shell
perl -MCPAN -e shell install DBIx::DBO2
For more information on module installation, please visit the detailed CPAN module installation guide.