1DBIx::Class::Helper::ReUssuelrtSCeotn:t:rOinbeuRtoewdD(B3PI)exr:l:CDloacsusm:e:nHtealtpieorn::ResultSet::OneRow(3)
2
3
4
6 DBIx::Class::Helper::ResultSet::OneRow - The first you always wanted
7
9 # note that this is normally a component for a ResultSet
10 package MySchema::ResultSet::Person;
11
12 use strict;
13 use warnings;
14
15 use parent 'DBIx::Class::ResultSet';
16
17 __PACKAGE__->load_components('Helper::ResultSet::OneRow');
18
19 sub person_named {
20 $_[0]->search({ name => $_[1] })->one_row
21 }
22
24 This component codifies an alternate version of "first" in
25 DBIx::Class::ResultSet. In practical use, "first" allows a user to do
26 something like the following:
27
28 my $rs = $schema->resultset('Foo')->search({ name => 'bar' });
29 my $first = $rs->first;
30 my @rest;
31 while (my $row = $rs->next) {
32 push @rest, $row
33 }
34
35 Problematically, if you call "first" without the while loop afterwards
36 and you got back more than one row, you are leaving a cursor open.
37 Depending on your database this could increase memory usage or cause
38 errors with later queries.
39
40 Fundamentally the difference is that when you use "one_row" you are
41 guaranteed to exhaust the underlying cursor.
42
43 Generally speaking, unless you are doing something unusual, "one_row"
44 is a good default.
45
47 one_row
48 Limits the ResultSet to a single row, and then returns the matching
49 result object. In case no rows match, "undef" is returned as normal.
50
52 Thanks to Aran Clary Deltac (BLUEFEET) for initially writing this
53 module, and thanks to ZipRecruiter <https://www.ziprecruiter.com> for
54 sponsoring that initial developmentl
55
57 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
58
60 This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
61
62 This is free software; you can redistribute it and/or modify it under
63 the same terms as the Perl 5 programming language system itself.
64
65
66
67perl v5.32.0 2020D-B0I7x-:2:8Class::Helper::ResultSet::OneRow(3)