1 package SQL::Translator::Generator::Role::DDL;
4 use SQL::Translator::Utils qw(header_comment);
6 requires '_build_type_map';
7 requires '_build_numeric_types';
8 requires '_build_unquoted_defaults';
9 requires '_build_sizeless_types';
16 has numeric_types => (
20 has sizeless_types => (
24 has unquoted_defaults => (
32 has add_drop_table => (
36 # would also be handy to have a required size set if there is such a thing
38 sub field_name { $_[0]->quote($_[1]->name) }
41 ( $_[1]->comments ? ('-- ' . $_[1]->comments . "\n ") : () )
45 my ($self, $table) = @_;
46 if ($self->add_comments) {
50 "-- Table: " . $self->quote($table->name) . "",
52 map "-- $_", $table->comments
59 sub field_nullable { ($_[1]->is_nullable ? $_[0]->nullable : 'NOT NULL' ) }
62 return () if !defined $_[1]->default_value;
64 my $val = $_[1]->default_value;
65 $val = "'$val'" unless $_[0]->numeric_types->{$_[1]->data_type};
66 return ( "DEFAULT $val" )
70 my ($self, $field) = @_;
72 my $field_type = $field->data_type;
73 ($self->type_map->{$field_type} || $field_type).$self->field_type_size($field)
77 my ($self, $field) = @_;
79 ($field->size && !$self->sizeless_types->{$field->data_type}
80 ? '(' . $field->size . ')'
86 my ($self, $table) = @_;
87 ( map $self->field($_), $table->get_fields )
91 my ($self, $table) = @_;
92 (map $self->index($_), $table->get_indices)
95 sub nullable { 'NULL' }
97 sub header_comments { header_comment() . "\n" if $_[0]->add_comments }