NAME
DustyDB::Model - model classes represent the tables in your database
VERSION
version 0.02
SYNOPSIS
use DustyDB;
my $db = DustyDB->new( path => 'foo.db' );
my $author = $db->model( 'Author' );
# Create a record
my $schwartz = $author->create( name => 'Randall Schwartz' );
# New record that hasn't been saved yet
my $chromatic = $author->construct( name => 'chromatic' );
# Load a record from the disk
my $the_damian = $author->load( 'Damian Conway' );
# Load all/many of the records
my @authors = $author->all;
my @d_authors = $author->all_where( name => qr/^d/i );
# Or as an iterator
my $authors = $autor->all;
while (my $author = $authors->next) {
print " - ", $author->name, "\n";
}
# Delete the record
$schwartz->delete;
DESCRIPTION
This class is the bridge between the storage database and the records in it. Normally, you won't need to create this object yourself, but use the model
method of DustyDB to create it for you.
ATTRIBUTES
class_name
This is the record package.
db
This is the DustyDB that owns this model instance.
METHODS
construct
Create a new record object in memory only. You need to call "save" in DustyDB::Record on the record to store it. The parameters are passed directly to the constructor for the record.
create
Create a new record object and save it. The parameters are passed to the constructor for the record.
load
Load a record object from the disk.
load_or_create
Load or create the object. It will use the keys in the given parameter hash to try and load an object. If that fails, it will use all the parameters to construct a new record and save it.
load_and_update_or_create
This is similar to "load_or_create", but it will also make sure that all of the passed parameters are set on the loaded object as well.
all
all_where
The "all" and "all_where" are synonyms. In list context, they will return a list of zero or more records. In scalar context they will return a DustyDB::Collection object. These methods will accept the same arguments as the "filter" in DustyDB::Collection method of that class.