1 |
package Frey::Collection; |
2 |
use Moose::Role; |
3 |
|
4 |
use Data::Dump qw/dump/; |
5 |
use Carp; |
6 |
|
7 |
sub collection { |
8 |
my ( $class, $args ) = @_; |
9 |
|
10 |
croak "expect HASH not ",dump( $args ) unless ref($args) eq 'HASH'; |
11 |
|
12 |
warn "## collection args = ",dump( $args ); |
13 |
|
14 |
my $schema = $class->SchemaClass()->Schema(); |
15 |
my $select = $class->SchemaClass()->SQLFactoryClass()->new_select(); |
16 |
|
17 |
my $table = $class->collection_table; |
18 |
|
19 |
warn "## table $table"; |
20 |
|
21 |
my $users_t = $schema->table( $table ); |
22 |
|
23 |
$select->select( $users_t ) |
24 |
->from( $users_t ) |
25 |
# ->where( $message_t->column('message_date'), '>=', |
26 |
# DateTime->today()->subtract( days => 7 )->strftime( '%Y-%m-%d' ) ) |
27 |
->limit( $args->{limit} || 20, $args->{offset} || 0 ) |
28 |
; |
29 |
|
30 |
my $dbh = $class->_dbh($select); |
31 |
|
32 |
my $sth = $dbh->prepare( $select->sql($dbh) ); |
33 |
|
34 |
return |
35 |
Fey::Object::Iterator->new( |
36 |
classes => [ $class->meta()->ClassForTable( $users_t ) ], |
37 |
handle => $sth, |
38 |
bind_params => [ $select->bind_params() ], |
39 |
); |
40 |
} |
41 |
|
42 |
1; |