From: Justin Hunter Date: Tue, 11 Aug 2009 21:45:10 +0000 (-0700) Subject: add compat methods X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=70ada8ac7ae70e09134d3b4886d858d791c557b0;p=dbsrgits%2FSQL-Translator-2.0-ish.git add compat methods --- diff --git a/lib/SQL/Translator/Object/Column.pm b/lib/SQL/Translator/Object/Column.pm index 53a908b..dde964b 100644 --- a/lib/SQL/Translator/Object/Column.pm +++ b/lib/SQL/Translator/Object/Column.pm @@ -1,7 +1,7 @@ use MooseX::Declare; class SQL::Translator::Object::Column { - use MooseX::Types::Moose qw(Bool HashRef Int Maybe Str); - use SQL::Translator::Types qw(Trigger); + use MooseX::Types::Moose qw(ArrayRef Bool HashRef Int Maybe Str); + use SQL::Translator::Types qw(ColumnSize Constraint Trigger); extends 'SQL::Translator::Object'; has 'name' => ( @@ -24,8 +24,9 @@ class SQL::Translator::Object::Column { has 'size' => ( is => 'rw', - isa => Maybe[Int], - required => 1 + isa => ColumnSize, + coerce => 1, + auto_deref => 1, ); has 'is_nullable' => ( @@ -57,6 +58,17 @@ class SQL::Translator::Object::Column { isa => Bool, default => 0 ); + + has 'is_foreign_key' => ( + is => 'rw', + isa => Bool, + default => 0 + ); + + has 'foreign_key_reference' => ( + is => 'rw', + isa => Constraint, + ); has 'trigger' => ( is => 'rw', @@ -68,4 +80,11 @@ class SQL::Translator::Object::Column { isa => HashRef, auto_deref => 1, ); + + around size(@args) { + $self->$orig(@args) if @args; + my @sizes = $self->$orig; + return wantarray ? @sizes + : join ',', @sizes; + } } diff --git a/lib/SQL/Translator/Object/ForeignKey.pm b/lib/SQL/Translator/Object/ForeignKey.pm index e3ed307..af1bd13 100644 --- a/lib/SQL/Translator/Object/ForeignKey.pm +++ b/lib/SQL/Translator/Object/ForeignKey.pm @@ -1,15 +1,32 @@ use MooseX::Declare; class SQL::Translator::Object::ForeignKey { - use SQL::Translator::Types qw(Index PrimaryKey); + use MooseX::Types::Moose qw(ArrayRef Maybe Undef Str); extends 'SQL::Translator::Object::Constraint'; has '+type' => ( - default => 'FOREIGN_KEY', + default => 'FOREIGN KEY', ); - has 'references' => ( - isa => PrimaryKey | Index, + has 'reference_columns' => ( + isa => ArrayRef | Undef, + is => 'rw', + auto_deref => 1 + ); + + has 'on_delete' => ( + isa => Maybe[Str], + is => 'rw', + ); + + has 'on_update' => ( + isa => Maybe[Str], + is => 'rw', + ); + + has 'reference_table' => ( + isa => Str, is => 'rw', - required => 1, ); + + method reference_fields { return $self->reference_columns } } diff --git a/lib/SQL/Translator/Object/Table.pm b/lib/SQL/Translator/Object/Table.pm index 2d2b0d3..4ca5c6b 100644 --- a/lib/SQL/Translator/Object/Table.pm +++ b/lib/SQL/Translator/Object/Table.pm @@ -108,4 +108,7 @@ class SQL::Translator::Object::Table { ); method get_fields { return $self->get_columns } + method primary_key(Str $column) { + $self->get_column($column)->is_primary_key(1); + } }