From: Arthur Axel 'fREW' Schmidt Date: Fri, 11 Mar 2011 02:44:10 +0000 (-0600) Subject: refactor table into more methods X-Git-Tag: v0.11011~27^2~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2ce8cf9bba5467173367d9fb6b9aab7b73532f86;p=dbsrgits%2FSQL-Translator.git refactor table into more methods --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLServer.pm b/lib/SQL/Translator/Generator/DDL/SQLServer.pm index 70782a2..e9433eb 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLServer.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLServer.pm @@ -142,25 +142,29 @@ sub enum_constraint { ) } +sub constraints { + my ($self, $table) = @_; + + (map $self->enum_constraint($_->name, { $_->extra }->{list} || []), + grep { 'enum' eq lc $_->data_type } $table->get_fields), + + (map $self->primary_key_constraint($_), + grep { $_->type eq PRIMARY_KEY } $table->get_constraints), + + (map $self->unique_constraint_single($_), + grep { + $_->type eq UNIQUE && + !grep { $_->is_nullable } $_->fields + } $table->get_constraints), +} + sub table { my ($self, $table) = @_; 'CREATE TABLE ' . $self->quote($table->name) . " (\n". join( ",\n", map { " $_" } - # field defs - ( map $self->field($_), $table->get_fields ), - # constraint defs - (map $self->enum_constraint($_->name, { $_->extra }->{list} || []), - grep { 'enum' eq lc $_->data_type } $table->get_fields), - - (map $self->primary_key_constraint($_), - grep { $_->type eq PRIMARY_KEY } $table->get_constraints), - - (map $self->unique_constraint_single($_), - grep { - $_->type eq UNIQUE && - !grep { $_->is_nullable } $_->fields - } $table->get_constraints), + $self->fields($table), + $self->constraints($table), ) . "\n);", } diff --git a/lib/SQL/Translator/Generator/Role/DDL.pm b/lib/SQL/Translator/Generator/Role/DDL.pm index 7b6726f..e8ddcf9 100644 --- a/lib/SQL/Translator/Generator/Role/DDL.pm +++ b/lib/SQL/Translator/Generator/Role/DDL.pm @@ -54,6 +54,11 @@ sub field_type { ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field) } +sub fields { + my ($self, $table) = @_; + ( map $self->field($_), $table->get_fields ) +} + sub nullable { 'NULL' } 1;