2 |
use Moose::Role; |
use Moose::Role; |
3 |
|
|
4 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
5 |
|
use Carp; |
6 |
|
|
7 |
sub collection { |
sub collection { |
8 |
my ( $class, $limit, $offset ) = @_; |
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(); |
my $schema = $class->SchemaClass()->Schema(); |
15 |
my $select = $class->SchemaClass()->SQLFactoryClass()->new_select(); |
my $select = $class->SchemaClass()->SQLFactoryClass()->new_select(); |
16 |
|
|
18 |
|
|
19 |
warn "## table $table"; |
warn "## table $table"; |
20 |
|
|
|
$limit ||= 20; |
|
|
$offset ||= 0; |
|
|
|
|
21 |
my $users_t = $schema->table( $table ); |
my $users_t = $schema->table( $table ); |
22 |
|
|
23 |
$select->select( $users_t ) |
$select->select( $users_t ) |
24 |
->from( $users_t ) |
->from( $users_t ) |
25 |
# ->where( $message_t->column('message_date'), '>=', |
# ->where( $message_t->column('message_date'), '>=', |
26 |
# DateTime->today()->subtract( days => 7 )->strftime( '%Y-%m-%d' ) ) |
# DateTime->today()->subtract( days => 7 )->strftime( '%Y-%m-%d' ) ) |
27 |
->limit( $limit, $offset ) |
->limit( $args->{limit} || 20, $args->{offset} || 0 ) |
28 |
; |
; |
29 |
|
|
30 |
my $dbh = $class->_dbh($select); |
my $dbh = $class->_dbh($select); |