Basset::DB::Table::View - used to define virtual views to your objects.


Basset documentation Contained in the Basset distribution.

Index


Code Index:

NAME

Top

Basset::DB::Table::View - used to define virtual views to your objects.

AUTHOR

Top

Jim Thomason, jim@jimandkoka.com

SYNOPSIS

Top

For example,

 my $table = Basset::DB::Table::View->new(
	'name'				=> 'user',
	'primary_column'	=> 'id',
	'select_query' => <<'	eSQL',
		select
			user.id,
			name,
			count(*) as movies
		from
			user, movies
		where
			user.id = movies.user
			and user.id = ?
		group by
			user.id, name
	eSQL
	'definition'		=> {
		'id'		=> 'SQL_INTEGER',
		'name'		=> 'SQL_VARCHAR',
		'movies'	=> 'SQL_INTEGER',
	}
 );

 Some::Class->add_primarytable($table);

 my $object = Some::Class->load(1);	#load by user 1
 print $object->id, "\n"; #id (user id)
 print $object->name, "\n"; #"Jack Sprat"
 print $object->movies, "\n"; #145 (he owns 145 movies)




DESCRIPTION

Top

Basset::DB::Table::View provides an abstract and consistent location for defining database views. Normally, your objects are mapped to tables (most frequently in a 1-1 manner), but sometimes it's convenient to hide a view of data behind an object. This way you can access a complex data query as if it were an object.

Basset::DB::Table::View as your primary table allows you to do that.

Naturally, by virtue of the fact that these are potentially complex queries, objects that use view tables are read-only.

ATTRIBUTES

Top

select_query

In view tables, the select_query is an attribute, not a method. You should explicitly define the select query that is used by this table view.

 $table->select_query('select * from somewhere');


Basset documentation Contained in the Basset distribution.
package Basset::DB::Table::View;

#Basset::DB::Table::View, copyright and (c) 2004 James A Thomason III
#Basset::DB::Table is distributed under the terms of the Perl Artistic License.

$VERSION = '1.00';

use Basset::DB::Table;
@ISA = qw(Basset::DB::Table);

use strict;
use warnings;

__PACKAGE__->add_attr('select_query');

sub insert_query {
	return shift->error("Views cannot insert", "BDTV-01");
}

sub replace_query {
	return shift->error("Views cannot replace", "BDTV-02");
}


sub update_query {
	return shift->error("Views cannot update", "BDTV-03");
}

sub delete_query {
	return shift->error("Views cannot delete", "BDTV-04");
}

sub multiselect_query {
	return shift->error("Views cannot multiselect", "BDTV-05");
}

sub attach_to_query {
	my $self	= shift;
	my $query	= shift;
	
	return $self->SUPER::attach_to_query($query);
}


1;