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