[Bast-commits] r5451 - in DBIx-Class/0.08/branches/views:
lib/DBIx/Class/ResultSource lib/SQL/Translator/Parser/DBIx
t/lib/DBICTest t/lib/DBICTest/Schema
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Wed Feb 11 14:38:08 GMT 2009
Author: castaway
Date: 2009-02-11 14:38:08 +0000 (Wed, 11 Feb 2009)
New Revision: 5451
Added:
DBIx-Class/0.08/branches/views/lib/DBIx/Class/ResultSource/View.pm
DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema/Year2000CDs.pm
Modified:
DBIx-Class/0.08/branches/views/lib/SQL/Translator/Parser/DBIx/Class.pm
DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema.pm
Log:
Original code
Added: DBIx-Class/0.08/branches/views/lib/DBIx/Class/ResultSource/View.pm
===================================================================
--- DBIx-Class/0.08/branches/views/lib/DBIx/Class/ResultSource/View.pm (rev 0)
+++ DBIx-Class/0.08/branches/views/lib/DBIx/Class/ResultSource/View.pm 2009-02-11 14:38:08 UTC (rev 5451)
@@ -0,0 +1,58 @@
+package DBIx::Class::ResultSource::View;
+
+use strict;
+use warnings;
+
+use DBIx::Class::ResultSet;
+
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/ResultSource/);
+__PACKAGE__->mk_group_accessors(
+ 'simple' => qw(is_virtual view_definition)
+);
+
+=head1 NAME
+
+DBIx::Class::ResultSource::Table - Table object
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+Table object that inherits from L<DBIx::Class::ResultSource>
+
+=head1 METHODS
+
+=head2 is_virtual
+
+Attribute to declare a view as virtual.
+
+=head2 from
+
+Returns the FROM entry for the table (i.e. the view name)
+or the definition if this is a virtual view.
+
+=cut
+
+sub from {
+ my $self = shift;
+ return \"(${\$self->view_definition})" if $self->is_virtual;
+ return $self->name;
+}
+
+1;
+
+=head1 AUTHORS
+
+Matt S. Trout <mst at shadowcatsystems.co.uk>
+
+With Contributions from:
+
+Guillermo Roditi E<lt>groditi at cpan.orgE<gt>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
+
Modified: DBIx-Class/0.08/branches/views/lib/SQL/Translator/Parser/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/branches/views/lib/SQL/Translator/Parser/DBIx/Class.pm 2009-02-11 13:47:06 UTC (rev 5450)
+++ DBIx-Class/0.08/branches/views/lib/SQL/Translator/Parser/DBIx/Class.pm 2009-02-11 14:38:08 UTC (rev 5451)
@@ -66,7 +66,18 @@
}
- foreach my $moniker (sort @monikers)
+ my(@table_monikers, @view_monikers);
+ for my $moniker (@monikers){
+ my $source = $dbicschema->source($moniker);
+ next if $source->is_virtual;
+ if ( $source->isa('DBIx::Class::ResultSource::Table') ) {
+ push(@table_monikers, $moniker);
+ } elsif( $source->isa('DBIx::Class::ResultSource::View') ){
+ push(@view_monikers, $moniker);
+ }
+ }
+
+ foreach my $moniker (sort @table_monikers)
{
my $source = $dbicschema->source($moniker);
@@ -218,6 +229,25 @@
$source->_invoke_sqlt_deploy_hook($table);
}
+ foreach my $moniker (sort @view_monikers)
+ {
+ my $source = $dbicschema->source($moniker);
+ # Skip custom query sources
+ next if ref($source->name);
+
+ # Its possible to have multiple DBIC source using same table
+ next if $seen_tables{$source->name}++;
+
+ my $view = $schema->add_view(
+ name => $source->name,
+ fields => [ $source->columns ],
+ $source->view_definition ? ( 'sql' => $source->view_definition ) : ()
+ );
+ if ($source->result_class->can('sqlt_deploy_hook')) {
+ $source->result_class->sqlt_deploy_hook($view);
+ }
+ }
+
if ($dbicschema->can('sqlt_deploy_hook')) {
$dbicschema->sqlt_deploy_hook($schema);
}
Added: DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema/Year2000CDs.pm
===================================================================
--- DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema/Year2000CDs.pm (rev 0)
+++ DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema/Year2000CDs.pm 2009-02-11 14:38:08 UTC (rev 5451)
@@ -0,0 +1,30 @@
+package # hide from PAUSE
+ DBICTest::Schema::Year2000CDs;
+
+use base 'DBIx::Class::Core';
+use DBIx::Class::ResultSource::View;
+
+__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
+
+__PACKAGE__->table('cd');
+__PACKAGE__->result_source_instance->view_definition(
+ "SELECT cdid, artist, title FROM cd WHERE year ='2000'"
+);
+__PACKAGE__->add_columns(
+ 'cdid' => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'artist' => {
+ data_type => 'integer',
+ },
+ 'title' => {
+ data_type => 'varchar',
+ size => 100,
+ },
+
+);
+__PACKAGE__->set_primary_key('cdid');
+__PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
+
+1;
Modified: DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema.pm 2009-02-11 13:47:06 UTC (rev 5450)
+++ DBIx-Class/0.08/branches/views/t/lib/DBICTest/Schema.pm 2009-02-11 14:38:08 UTC (rev 5451)
@@ -18,6 +18,7 @@
#dummy
Track
Tag
+ Year2000CDs
/,
{ 'DBICTest::Schema' => [qw/
LinerNotes
More information about the Bast-commits
mailing list