[Dbix-class] Removing rows older than a given number of minutes ...

Kiffin Gish kiffin.gish at planet.nl
Tue Jan 26 17:22:56 GMT 2010


The lazy man's way out is:

use DateTime;
use DateTime::Duration;

my @users = $rs->search({state=>$state});
for my $user (@users) {
    my $duration = DateTime::Duration->new(DateTime->now -
$user->last_modified);
    $user->delete if ($duration->seconds > $limit);
}

Probably more generic rather than hard-coding SQL stuff.


On Sun, 2010-01-24 at 11:21 -0500, Rob Kinyon wrote:
> On Sun, Jan 24, 2010 at 02:44, Octavian Rasnita <octavian at fcc.ro> wrote:
> > From: "Rob Kinyon" <rob.kinyon at gmail.com>
> >> $rs->search({
> >>   state => $state,
> >>   last_modified => [ "< TIMEDIFF( NOW(), ? SECONDS", $seconds ],
> >> })->delete_all;
> >>
> >> Standard SQL::Abstract stuff, described in both the DBIC cookbook and
> >> the SQL::Abstract docs.
> >
> > Is the following SQL
> >
> > < TIMEDIFF( NOW(), ? SECONDS
> >
> > a standard SQL code supported by more databases?
> 
> The point I was trying to make is that the stuff in the quotes is
> literal SQL. So, whatever your DBMS needs to determine a difference
> between two times. I used MySQL-specific syntax, but the concept
> transfers.
> 
> Rob
> 
> _______________________________________________
> 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.scsys.co.uk


-- 
Kiffin Gish <Kiffin.Gish at planet.nl>
Gouda, The Netherlands





More information about the DBIx-Class mailing list