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

Lianna Eeftinck liannaee at gmail.com
Thu Feb 12 12:25:55 GMT 2015


Or just use ->count, which doesn't need to retrieve and instantiate the
objects.

On 12 February 2015 at 11:33, Dmitry L. <dim0xff at gmail.com> wrote:

> On 12 February 2015 at 14:27, Hartmaier Alexander
> <alexander.hartmaier at t-systems.at> wrote:
> > I'd additinally restrict the columns returned to the pk columns to save
> > bytes going over the wire and using HRI to not instantiate a result
> object.
> >
> > Looks like a nice addition to DBIC::Helpers!
> >
> Looks like already there: DBIx::Class::Helper::ResultSet::Shortcut::HasRows
>
>
> >
> > On 2015-02-12 08:22, QE :: Felix Ostmann wrote:
> >
> > 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
> >
> >
> >
> >
> > _______________________________________________
> > 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
> >
> >
> >
> >
> >
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> > T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> > Handelsgericht Wien, FN 79340b
> >
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> > Notice: This e-mail contains information that is confidential and may be
> > privileged.
> > If you are not the intended recipient, please notify the sender and then
> > delete this e-mail immediately.
> >
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> >
> > _______________________________________________
> > 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
>
>
>
> --
> //wbr, Dmitry L.
>
> _______________________________________________
> 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/a631d666/attachment.htm>


More information about the DBIx-Class mailing list