DELETE .... RETURNING

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DELETE .... RETURNING

Bill Moseley
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.

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?


--
Bill Moseley
[hidden email]

_______________________________________________
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@...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DELETE .... RETURNING

Peter Rabbitson-2
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!

_______________________________________________
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@...
Loading...