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

QE :: Felix Ostmann ostmann at qe.de
Thu Feb 12 07:22:11 GMT 2015


We are using this function in our ResultSet.pm:

sub exists {
    my ($self, $query) = @_;

    return $self->search($query, { rows => 1, select => [\1] })->single;
}


Have a nice day
Felix


2015-02-12 1:05 GMT+01:00 Charlie Garrison <garrison at zeta.org.au>:

> 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
>
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150212/6027a4ca/attachment.htm>


More information about the DBIx-Class mailing list