Skip to content

Instantly share code, notes, and snippets.

@TristinDavis
Created November 16, 2012 01:41
Show Gist options
  • Save TristinDavis/4083155 to your computer and use it in GitHub Desktop.
Save TristinDavis/4083155 to your computer and use it in GitHub Desktop.
DBIx::Class::Candy +MoreSugar
package Application::Model::Sugar;
# common sugar routines
sub serial {
my %chngs = @_;
my %attrs = ('data_type', 'integer', 'is_auto_increment', 1, null() );
$attrs{$_} = $chngs{$_} for keys %chngs;
return %chngs;
}
sub datetime {
my %chngs = @_;
my %attrs = ( 'data_type', 'datetime', 'datetime_undef_if_invalid', 1 );
$attrs{$_} = $chngs{$_} for keys %chngs;
return %chngs;
}
sub string {
my %chngs = @_;
my %attrs = ('data_type', 'varchar', 'size', 255, 'is_nullable', 0 );
$attrs{$_} = $chngs{$_} for keys %chngs;
return %chngs;
}
sub number {
my %chngs = @_;
my %attrs = ('data_type', 'integer', 'size', 11, 'is_nullable', 0 );
$attrs{$_} = $chngs{$_} for keys %chngs;
return %chngs;
}
sub null {
return ('default', undef, 'is_nullable', 1);
}
eval {
require 'DBIx::Class::Candy::Exports';
DBIx::Class::Candy::Exports->import;
DBIx::Class::Candy::Exports::export_methods(
[qw/serial datetime string number null/] );
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment