DBIx::Skinny::Schema::ProxyTableRule
package Proj::DB::Schema; use DBIx::Skinny::Schema; use DBIx::Skinny::Schema::ProxyTableRule; install_table 'access_log' => shcema { proxy_table_rule 'named_strftime', 'access_log_%Y%m', 'accessed_on'; pk 'id'; columns qw/id/; }; package main; my $rule = Proj::DB->proxy_table->rule('access_log', accessed_on => DateTime->today); $rule->table_name; #=> "access_log_200901" # create table that name is "access_log_200901" $rule->copy_table; my $iter = Proj::DB->search($rule->table_name, { foo => 'bar' });
DBIx::Skinny::Schema::ProxyTableRule export proxy_table_rule method. You can call proxy_table_rule method in install_table method.
1st argumet is funtion name (strftime or sprintf) or CODEREF
If you define rule followings: package Proj::DB::Schema; use DBIx::Skinny::Schema; use DBIx::Skinny::Schema::ProxyTableRule;
install_table 'access_log' => schema { proxy_table_rule 'named_strftime', 'access_log_%Y%m', 'accessed_on'; };
you can call followings:
my $rule = Proj::DB->proxy_table->rule('access_log', accessed_on => DateTime->now); $rule->table_name #=> "access_log_201002"
install_table 'access_log' => schema { proxy_table_rule 'keyword', 'access_log_<%04d:year><%02d:month>'; };
my $now = DateTime->now; my $rule = Proj::DB->proxy_table->rule('access_log', year => $now->year, month => $now->month); $rule->table_name #=> "access_log_201002"
second argument's format is like <sprintf_format:keyword_key>. Each keywords are replaced by CORE::sprintf.
install_table 'access_log' => schema { proxy_table_rule 'sprintf', 'access_log_%04d%02d'; };
my $now = DateTime->now; my $rule = Proj::DB->proxy_table->rule('access_log', $now->year, $now->month); $rule->table_name #=> "access_log_201002"
I recommend to use keyword, than this. If you make mistake to specify argument order, it may cause some problem.
install_table 'access_log' => schema { proxy_table_rule 'strftime', 'access_log_%Y%m'; };
my $rule = Proj::DB->proxy_table->rule('access_log', DateTime->now); $rule->table_name #=> "access_log_201002"
I recommend to use named_strftime, than this. If you make mistake to send rule to not accessed_on but created_on, it may cause some problem.
You can define custom function.
my $code = sub { my ($template, @args) = @_; sprintf($template, @args); }; install_table 'access_log' => schema { proxy_table_rule \$code, 'access_log_%02d%02d'; };
Keiji Yoshimi <walf443 at gmail dot com>
DBIx::Skinny::ProxyTable, DBIx::Skinny::ProxyTable::Rule
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::Skinny::ProxyTable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Skinny::ProxyTable
CPAN shell
perl -MCPAN -e shell install DBIx::Skinny::ProxyTable
For more information on module installation, please visit the detailed CPAN module installation guide.