[Dbix-class] Fastest method to check for key existence?

Charlie Garrison garrison at zeta.org.au
Thu Feb 12 00:05:20 GMT 2015


Good morning,

On 11/2/15 at 10:58 PM +0100, Ekki Plicht (DF4OR) <ekki at plicht.de> wrote:

>I am thinking of setting up a special resultset which contains only
>the key as a returned value by SELECT, but I am wondering if there is
>a faster method.

Put a method in your ResultSet class, eg:

sub key_exists {
    my ($self, $key) = @_;
    my $row = $self->find( $key );
    return $row ? 1 : 0;
}


Elsewhere:

my $got_row = $schema->resultset('RSClass')->key_exists($key);


Charlie

-- 
   Charlie Garrison  <garrison at zeta.org.au>
   github.com/cngarrison   metacpan.org/author/CNG

O< ascii ribbon campaign - stop html mail
http://www.ietf.org/rfc/rfc1855.txt




More information about the DBIx-Class mailing list