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   prefetch
163        $foo_rs->prefetch('bar');
164
165        # equivalent to...
166        $foo_rs->search(undef, { prefetch => 'bar' });
167
168   results_exist
169        my $results_exist = $schema->resultset('Bar')->search({...})->results_exist;
170
171        # there is no easily expressable equivalent, so this is not exactly a
172        # shortcut. Nevertheless kept in this class for historical reasons
173
174       Uses "EXISTS" SQL function to check if the query would return anything.
175       Usually much less resource intensive the more common "foo() if
176       $rs->count" idiom.
177
178   results_exist_as_query
179        ...->search(
180           {},
181           { '+columns' => {
182              subquery_has_members => $some_correlated_rs->results_exist_as_query
183           }},
184        );
185
186        # there is no easily expressable equivalent, so this is not exactly a
187        # shortcut. Nevertheless kept in this class for historical reasons
188
189       The query generator behind "results_exist". Can be used standalone in
190       complex queries returning a boolean result within a larger query
191       context.
192
193   null(@columns || \@columns)
194        $rs->null('status');
195        $rs->null(['status', 'title']);
196
197   not_null(@columns || \@columns)
198        $rs->not_null('status');
199        $rs->not_null(['status', 'title']);
200
201   like($column || \@columns, $cond)
202        $rs->like('lyrics', '%zebra%');
203        $rs->like(['lyrics', 'title'], '%zebra%');
204
205   not_like($column || \@columns, $cond)
206        $rs->not_like('lyrics', '%zebra%');
207        $rs->not_like(['lyrics', 'title'], '%zebra%');
208

AUTHOR

210       Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
211
213       This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
214
215       This is free software; you can redistribute it and/or modify it under
216       the same terms as the Perl 5 programming language system itself.
217
218
219
220perl v5.30.1                      20D2B0I-x0:1:-C2l9ass::Helper::ResultSet::Shortcut(3)
Impressum