1DBIx::Class::Helper::ReUssuelrtSCeotn:t:rSihbourtDteBcdIuxtP:(e:3rC)llaDsosc:u:mHeenltpaetri:o:nResultSet::Shortcut(3)
2
3
4
6 DBIx::Class::Helper::ResultSet::Shortcut - Shortcuts to common searches
7 (->order_by, etc)
8
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
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
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
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 Uses "EXISTS" SQL function to check if the query would return anything.
172 Possibly lighter weight than the much more common "foo() if $rs->count"
173 idiom.
174
175 null(@columns || \@columns)
176 $rs->null('status');
177 $rs->null(['status', 'title']);
178
179 not_null(@columns || \@columns)
180 $rs->not_null('status');
181 $rs->not_null(['status', 'title']);
182
183 like($column || \@columns, $cond)
184 $rs->like('lyrics', '%zebra%');
185 $rs->like(['lyrics', 'title'], '%zebra%');
186
187 not_like($column || \@columns, $cond)
188 $rs->not_like('lyrics', '%zebra%');
189 $rs->not_like(['lyrics', 'title'], '%zebra%');
190
192 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
193
195 This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
196
197 This is free software; you can redistribute it and/or modify it under
198 the same terms as the Perl 5 programming language system itself.
199
200
201
202perl v5.30.0 20D1B9I-x0:8:-C3l0ass::Helper::ResultSet::Shortcut(3)