NAME

DBIx::Skinny::Schema::ProxyTableRule

SYNOPSIS

package Proj::DB::Schema;
use DBIx::Skinny::Schema;
use DBIx::Skinny::Schema::ProxyTableRule;

install_table 'access_log' => shcema {
  proxy_table_rule 'strftime', 'access_log_%Y%m';

  pk 'id';
  columns qw/id/;
};

package main;

my $rule = Proj::DB->proxy_table->rule('access_log', 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' });

DESCRIPTION

DBIx::Skinny::Schema::ProxyTableRule export proxy_table_rule method. You can call proxy_table_rule method in install_table method.

METHOD

proxy_table_rule($funcname_or_coderef, @default_args)

1st argumet is funtion name (strftime or sprintf) or CODEREF

strftime

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 'strftime', 'access_log_%Y%m';
};

you can call followings:

my $rule = Proj::DB->proxy_table->rule('access_log', DateTime->now);
$rule->table_name #=> "access_log_201002"

sprintf

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 'sprintf', 'access_log_%04d%02d';
};

you can call followings:

my $now = DateTime->now;
my $rule = Proj::DB->proxy_table->rule('access_log', $now->year, $now->month);
$rule->table_name #=> "access_log_201002"

CODEREF

You can define custom function.

If you define rule followings: package Proj::DB::Schema; use DBIx::Skinny::Schema; use DBIx::Skinny::Schema::ProxyTableRule;

my $code = sub {
    my ($template, @args) = @_;
    sprintf($template, @args);
};
install_table 'access_log' => schema {
    proxy_table_rule \$code, 'access_log_%02d%02d';
};

you can call followings:

my $now = DateTime->now;
my $rule = Proj::DB->proxy_table->rule('access_log', $now->year, $now->month);
$rule->table_name #=> "access_log_201002"

AUTHOR

Keiji Yoshimi <walf443 at gmail dot com>

SEE ALSO

+<DBIx::Skinny::ProxyTable>, +<DBIx::Skinny::ProxyTable::Rule>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.