Commit | Line | Data |
7e179591 |
1 | package SQL::Translator::Producer::SQLite; |
2 | use namespace::autoclean; |
3 | use Moose::Role; |
4 | |
44547961 |
5 | sub _create_table { |
6 | my $self = shift; |
7 | my $table = shift; |
8 | |
9 | my $no_comments = 0; |
10 | my $add_drop_table = 1; |
11 | my $sqlite_version = 0; |
12 | |
13 | my $create_table; |
14 | my (@create, @column_defs, @index_defs, @constraint_defs); |
15 | |
16 | $create_table .= 'DROP TABLE ' . $table->name . ";\n" if $add_drop_table; |
17 | $create_table .= 'CREATE TABLE ' . $table->name . " (\n"; |
18 | |
19 | push @column_defs, $self->_create_column($_) for values %{$table->columns}; |
20 | $create_table .= join(",\n", map { ' ' . $_ } @column_defs ) . "\n)"; |
21 | |
22 | print $create_table . "\n"; |
23 | return (@create, $create_table, @index_defs, @constraint_defs ); |
24 | } |
25 | |
26 | sub _create_column { |
27 | my $self = shift; |
28 | my $column = shift; |
29 | |
30 | my $size = $column->data_type =~ /^(timestamp)/i ? undef : $column->size; |
31 | |
32 | my $column_def; |
33 | $column_def = $column->name . ' ' . $column->data_type; |
34 | $column_def .= '(' . $column->size . ')' if $size; |
35 | $column_def .= ' NOT NULL' unless $column->is_nullable; |
36 | $column_def .= ' DEFAULT ' . $column->default_value if $column->default_value; |
37 | $column_def; |
38 | } |
39 | |
7e179591 |
40 | 1; |