[Dbix-class] Fastest method to check for key existence?
Hartmaier Alexander
alexander.hartmaier at t-systems.at
Thu Feb 12 11:27:24 GMT 2015
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!
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<mailto:garrison at zeta.org.au>>:
Good morning,
On 11/2/15 at 10:58 PM +0100, Ekki Plicht (DF4OR) <ekki at plicht.de<mailto: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<mailto:garrison at zeta.org.au>>
github.com/cngarrison<http://github.com/cngarrison> metacpan.org/author/CNG<http://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<http://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.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20150212/2bb6d7cf/attachment.htm>
More information about the DBIx-Class
mailing list