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

Ekki Plicht (DF4OR) ekki at plicht.de
Fri Feb 13 11:13:13 GMT 2015


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



More information about the DBIx-Class mailing list