[Dbix-class] DELETE .... RETURNING

Peter Rabbitson rabbit+dbic at rabbit.us
Sat Feb 20 08:01:33 GMT 2016


On 02/20/2016 01:12 AM, Bill Moseley wrote:
> Two related questions.
>
> First,  I have a resultset where I want to call $rs->delete_all and I'd
> like to know specifically which rows got deleted.    RETURNING works for
> this, of course, but wondering if there's a way in DBIC to do this.

Not at present, no. I do not have immediate plans for this, as it would 
require a news set of APIs, or something similarly clever... Likely 
something for whoever comes after me.

> In a similar way we often will update or insert and then
> ->discard_changes to fetch updated row, but that's two queries.   Any
> way to do more than just RETURNING id?

If you are using an engine supporting RETURNING - the PK is already 
fetched for you behind the scenes this way (you can see that in the 
trace). In addition there is 
https://metacpan.org/pod/DBIx::Class::ResultSource#retrieve_on_insert 
which will add any column you want to the RETURNING statement.

There is currently no similar functionality for retrieve_on_update. I 
*may* be able to sneak it in, but can't promise yet.

Cheers!



More information about the DBIx-Class mailing list