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

Nic Gibson nicg at corbas.net
Thu Nov 22 14:48:55 GMT 2007


Matt

Deeply embarrassed about not saying thanks for the pointers.

I've been sidetracked onto a different project for about a month
(involving about 100gigs of digitised Penguin books). I'm going to
give it all a try later this week.

cheers

nic

On 10/18/07, Matt S Trout <dbix-class at trout.me.uk> wrote:
> 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/
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>


-- 
Nic Gibson
Director, Corbas Consulting
Editorial and Technical Consultancy
http://www.corbas.co.uk/



More information about the DBIx-Class mailing list