[DBIx-Class-Devel] UPDATE RETURNING

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Jul 15 15:25:46 GMT 2013


On Mon, Jul 15, 2013 at 10:13:11AM -0500, fREW Schmidt wrote:
> I just found out about UPDATE RETURNING (and the various dialects
> thereof, of course) and I'm aching to use it in DBIC.  What do you
> guys think about something like this?
> 
> my @rows = $rs->update({ .... }, { columns => $columns_spec })->all;

What is the actual use-case here? I understand what the construct does,
I am not sure how it is useful in practice.

In either case it can't go into DBIC proper under the same name - having
$rs->update() change its RV drastically depending on the attributes is
going to make stuff too confusing.

If you go for an extension then there are no limitations (though 
changing the RV of update is still in bad taste, as stuff higher up may 
rely on it).

> It should be able to use select/as too, fwiw.

I am not sure what this comment implies...

> 
> The main problem I see here is that this critically changes update from
> an immediate db hit to a typical lazy resultset.  It might be fine to
> call execute immediately either way and then the user can either use
> the returned RS or not.

I am not sure what you mean - $rs->update is immediate, there is no
lazified step...

>  That brings up another issue, that it throws
> away the rv, which I certainly leverage in a few places in my app.

QED

> 
> The other obvious and safe use case is to add another thing to the column
> definitions so that when a user calls $row->update the row object can
> have it's guts automatically updated.

This is quote separate and something that can be cleanly folded in (and 
be emulated on lesser RDBMS) - see the current implementation of 
retrieve_on_insert. I would not mind the column attribute to be extended 
with a retrieve_on_update boolean.

Cheers




More information about the DBIx-Class-Devel mailing list