1DBIx::Class::Helper::ReUssuelrtSCeotn:t:rSihbourtDteBcdIuxtP:(e:3rC)llaDsosc:u:mHeenltpaetri:o:nResultSet::Shortcut(3)
2
3
4

NAME

6       DBIx::Class::Helper::ResultSet::Shortcut - Shortcuts to common searches
7       (->order_by, etc)
8

SYNOPSIS

10        package MyApp::Schema::ResultSet::Foo;
11
12        __PACKAGE__->load_components(qw{Helper::ResultSet::Shortcut});
13
14        ...
15
16        1;
17
18       And then elsewhere:
19
20        # let's say you grab a resultset from somewhere else
21        my $foo_rs = get_common_rs()
22        # but I'd like it sorted!
23          ->order_by({ -desc => 'power_level' })
24        # and without those other dumb columns
25          ->columns([qw/cromulence_ratio has_jimmies_rustled/])
26        # but get rid of those duplicates
27          ->distinct
28        # and put those straight into hashrefs, please
29          ->hri
30        # but only give me the first 3
31          ->rows(3);
32

DESCRIPTION

34       This helper provides convenience methods for resultset modifications.
35
36       See "NOTE" in DBIx::Class::Helper::ResultSet for a nice way to apply it
37       to your entire schema.
38

SEE ALSO

40       This component is actually a number of other components put together.
41       It will get more components added to it over time.  If you are worried
42       about all the extra methods you won't use or something, using the
43       individual shortcuts is a simple solution.  All the documentation will
44       remain here, but the individual components are:
45
46       • DBIx::Class::Helper::ResultSet::Shortcut::HRI
47
48       • DBIx::Class::Helper::ResultSet::Shortcut::OrderBy
49
50       • DBIx::Class::Helper::ResultSet::Shortcut::OrderByMagic
51
52         (adds the "magic string" functionality to
53         "DBIx::Class::Helper::ResultSet::Shortcut::OrderBy"))
54
55       • DBIx::Class::Helper::ResultSet::Shortcut::GroupBy
56
57       • DBIx::Class::Helper::ResultSet::Shortcut::Distinct
58
59       • DBIx::Class::Helper::ResultSet::Shortcut::Rows
60
61       • DBIx::Class::Helper::ResultSet::Shortcut::Limit
62
63         (inherits from "DBIx::Class::Helper::ResultSet::Shortcut::Rows")
64
65       • DBIx::Class::Helper::ResultSet::Shortcut::HasRows
66
67         (inherits from "DBIx::Class::Helper::ResultSet::Shortcut::Rows")
68
69       • DBIx::Class::Helper::ResultSet::Shortcut::Columns
70
71       • DBIx::Class::Helper::ResultSet::Shortcut::AddColumns
72
73       • DBIx::Class::Helper::ResultSet::Shortcut::Page
74
75       • DBIx::Class::Helper::ResultSet::Shortcut::LimitedPage
76
77         (inherits from "DBIx::Class::Helper::ResultSet::Shortcut::Page" and
78         DBIx::Class::Helper::ResultSet::Shortcut::Rows)
79
80       • DBIx::Class::Helper::ResultSet::Shortcut::ResultsExist
81

METHODS

83   distinct
84        $foo_rs->distinct
85
86        # equivalent to...
87        $foo_rs->search(undef, { distinct => 1 });
88
89   group_by
90        $foo_rs->group_by([ qw/ some column names /])
91
92        # equivalent to...
93        $foo_rs->search(undef, { group_by => [ qw/ some column names /] });
94
95   order_by
96        $foo_rs->order_by({ -desc => 'col1' });
97
98        # equivalent to...
99        $foo_rs->search(undef, { order_by => { -desc => 'col1' } });
100
101       You can also specify the order as a "magic string", e.g.:
102
103        $foo_rs->order_by('!col1')       # ->order_by({ -desc => 'col1' })
104        $foo_rs->order_by('col1,col2')   # ->order_by([qw(col1 col2)])
105        $foo_rs->order_by('col1,!col2')  # ->order_by([{ -asc => 'col1' }, { -desc => 'col2' }])
106        $foo_rs->order_by(qw(col1 col2)) # ->order_by([qw(col1 col2)])
107
108       Can mix it all up as well:
109
110        $foo_rs->order_by(qw(col1 col2 col3), 'col4,!col5')
111
112   hri
113        $foo_rs->hri;
114
115        # equivalent to...
116        $foo_rs->search(undef, {
117           result_class => 'DBIx::Class::ResultClass::HashRefInflator'
118        });
119
120   rows
121        $foo_rs->rows(10);
122
123        # equivalent to...
124        $foo_rs->search(undef, { rows => 10 })
125
126   limit
127       This is an alias for "rows".
128
129         $foo_rs->limit(10);
130
131         # equivalent to...
132         $foo_rs->rows(10);
133
134   has_rows
135       A lighter way to check the resultset contains any data rather than
136       calling "$rs->count".
137
138   page
139        $foo_rs->page(2);
140
141        # equivalent to...
142        $foo_rs->search(undef, { page => 2 })
143
144   limited_page
145        $foo_rs->limited_page(2, 3);
146
147        # equivalent to...
148        $foo_rs->search(undef, { page => 2, rows => 3 })
149
150   columns
151        $foo_rs->columns([qw/ some column names /]);
152
153        # equivalent to...
154        $foo_rs->search(undef, { columns => [qw/ some column names /] });
155
156   add_columns
157        $foo_rs->add_columns([qw/ some column names /]);
158
159        # equivalent to...
160        $foo_rs->search(undef, { '+columns' => [qw/ some column names /] });
161
162   remove_columns
163        $foo_rs->remove_columns([qw/ some column names /]);
164
165        # equivalent to...
166        $foo_rs->search(undef, { remove_columns => [qw/ some column names /] });
167
168   prefetch
169        $foo_rs->prefetch('bar');
170
171        # equivalent to...
172        $foo_rs->search(undef, { prefetch => 'bar' });
173
174   results_exist($cond?)
175        my $results_exist = $schema->resultset('Bar')->search({...})->results_exist;
176
177        # there is no easily expressable equivalent, so this is not exactly a
178        # shortcut. Nevertheless kept in this class for historical reasons
179
180       Uses "EXISTS" SQL function to check if the query would return anything.
181       Usually much less resource intensive the more common "foo() if
182       $rs->count" idiom.
183
184       The optional $cond argument can be used like in search().
185
186   results_exist_as_query($cond?)
187        ...->search(
188           {},
189           { '+columns' => {
190              subquery_has_members => $some_correlated_rs->results_exist_as_query
191           }},
192        );
193
194        # there is no easily expressable equivalent, so this is not exactly a
195        # shortcut. Nevertheless kept in this class for historical reasons
196
197       The query generator behind "results_exist". Can be used standalone in
198       complex queries returning a boolean result within a larger query
199       context.
200
201   null(@columns || \@columns)
202        $rs->null('status');
203        $rs->null(['status', 'title']);
204
205   not_null(@columns || \@columns)
206        $rs->not_null('status');
207        $rs->not_null(['status', 'title']);
208
209   like($column || \@columns, $cond)
210        $rs->like('lyrics', '%zebra%');
211        $rs->like(['lyrics', 'title'], '%zebra%');
212
213   not_like($column || \@columns, $cond)
214        $rs->not_like('lyrics', '%zebra%');
215        $rs->not_like(['lyrics', 'title'], '%zebra%');
216

AUTHOR

218       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
219
221       This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
222
223       This is free software; you can redistribute it and/or modify it under
224       the same terms as the Perl 5 programming language system itself.
225
226
227
228perl v5.38.0                      20D2B3I-x0:7:-C2l0ass::Helper::ResultSet::Shortcut(3)
Impressum