[Dbix-class] Dynamic View

Benjamin Martin benjamin.martin at ims-evolve.com
Wed Dec 22 17:09:35 GMT 2010


hello all,

I have a table in my schema that holds SQL queries (horrid I know!). 
Imagine a table with query_id and query_sql columns.

I want to create a dynamic view within my schema that represents these 
queries. .. so I will be able to do something like this:

   my $query = $schema->resultset('TableHoldingQueries')->find(1);
   my $view = $query->as_view();
   my $row_from_running_query = $view->search()->first();

So the rough plan is in my 'TableHoldingQueries' Result file, I will 
create a method called, 'as_view'

   sub as_view
   {
     my $self = shift
     my $view = DBIx::Class::ResultSource::View->new( { .. } );
     $view->result_source_instance->is_virtual(1);
     $view->result_source_instance->view_definition( $self->query_sql );
     return $view;
   }

My problem is that I dont have a clue where to start creating a 
DBIx::Class::ResultSource::View on the fly in the correct way ... can 
anyone point me to some docs/examples .. anything ..

Thanks for any help you can provide.

Happy Xmas all =:-D

-B



More information about the DBIx-Class mailing list