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

QE :: Felix Ostmann ostmann at qe.de
Fri Feb 13 11:36:09 GMT 2015


I often build a map and use this also for an exist()-check (not for bigdata)

my %email_for =
    map { $@_ }
    $rs
        ->search(
            undef,
            {
                select => qw[ user_id email ],
            },
         )
        ->cursor
        ->all
    ;

only important is to use exact 2 fields in the select.



Mit freundlichem Gruß
Felix Ostmann


2015-02-13 12:13 GMT+01:00 Ekki Plicht (DF4OR) <ekki at plicht.de>:

> Ooookay... that's a lot of very helpful answers. Many thanks for all
> the suggestions, I guess I will go with the helper or with count().
>
> Thanks,
> Ekki
>
>
> 2015-02-13 11:32 GMT+01:00 Will Crawford <billcrawford1970 at gmail.com>:
> > On 11 February 2015 at 21:58, Ekki Plicht (DF4OR) <ekki at plicht.de>
> wrote:
> >> Hi,
> >> I need to check a list of values if they exist in a database. The
> >> value is a unique key of that table. A stupid 'find' works of course,
> >> but returns the whole row data, where I only need a simple binary
> >> yes/no information if a row was found or not.
> >
> > Presuming you mean that you need to get a list of them all, there's a
> > few answers, depending on your needs. A couple of the answers already
> > given are pretty useful and I'll be filing the "exists" rs method away
> > for future use.
> >
> > Something like
> >
> >     my %found = map +( $_ => 1 ),
> >         $rs->search_rs( { key => { -in => [ ... ] } }
> )->get_column('key')->all;
> >
> > might do the trick (not tested for typos).
> >
> > _______________________________________________
> > 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
>
> _______________________________________________
> 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/20150213/40552e6a/attachment.htm>


More information about the DBIx-Class mailing list