Last active
August 29, 2015 14:06
-
-
Save SysPete/b8c3c0e13d02b307de06 to your computer and use it in GitHub Desktop.
overloading Interchange6 schema result classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
package Interchange6::Schema; | |
use strict; | |
use warnings; | |
use base 'DBIx::Class::Schema'; | |
use Interchange6::Schema::Result::Order; | |
use Interchange6::Schema::Result::Product; | |
use Time::Duration; | |
use Time::Duration::Parse; | |
Interchange6::Schema::Result::Order->add_columns( | |
start_date => { | |
data_type => "date", | |
is_nullable => 1, | |
}, | |
end_date => { | |
data_type => "date", | |
is_nullable => 1, | |
}, | |
site => { | |
data_type => "varchar", | |
is_nullable => 1, | |
length => 255, | |
}, | |
); | |
Interchange6::Schema::Result::Product->load_components( | |
qw( FilterColumn InflateColumn::DateTime TimeStamp ) | |
); | |
Interchange6::Schema::Result::Product->add_columns( | |
min_age => { | |
data_type => "integer", | |
is_nullable => 1, | |
}, | |
duration => { | |
data_type => "integer", | |
is_nullable => 1, | |
}, | |
dives => { | |
data_type => "integer", | |
is_nullable => 0, | |
default => 0, | |
}, | |
elearning => { | |
data_type => "varchar", | |
is_nullable => 1, | |
size => 8, | |
}, | |
); | |
Interchange6::Schema::Result::Product->filter_column( | |
duration => { | |
filter_from_storage => sub { | |
my ( $self, $value ) = @_; | |
return undef unless $value; | |
return duration($value); | |
}, | |
filter_to_storage => sub { | |
my ( $self, $value ) = @_; | |
return undef unless $value; | |
return parse_duration($value); | |
}, | |
} | |
); | |
__PACKAGE__->load_namespaces; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment