NAME

DustyDB::Model - model classes represent the tables in your database

VERSION

version 0.01

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.

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.