[Dbix-class] CDBI->DBIx::Class migration question

Matt S Trout dbix-class at trout.me.uk
Thu Oct 18 18:48:09 GMT 2007


On Thu, Oct 18, 2007 at 07:34:22AM +0100, Nic Gibson wrote:
> Good morning
> 
> I'm in the middle of moving a large bunch of code from CDBI to
> DBIx::Class. Pretty
> well everything has worked perfectly except...
> 
> We have a stored procedure wrapper for CDBI. It allows us to create
> functions, accessors  and mutators that call SPs (in PostgreSQL).
> 
> We can mostly emulate this by creating resultsources I reckon.
> I'm wondering if there is a DBIx::Class way to handle mutators. In CDBI we have
> something like:
> 
> __PACKAGE__->sp_mutator(method_name =>
> 	{procedure => 'procname',
> 	argcount => 2,
> 	modifies => [qw/list of columns/]});
> 	
> which creates sql something like:
> 
> 	'select * from procname(?, ?, ?)'
> 	
> where procname has side effects that change the source table (the number of
> arguments being 'argcount' plus the number of primary key columns).
> 
> Then, in code, we can do
> 
> 	$object->method_name($arg1, $arg2);

Little bit brute force but how about just generating

sub method_name {
  my ($self, @args) = @_;
  $self->result_source->storage->dbh_do(sub {
    shift->do(
      'select * from procname(?, ?, ?)',
      (map { $self->$_ } $self->primary_columns),
      @args
    );
  });
  $self->discard_changes; # re-selects all columns
}

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list