2 class SQL::Translator::Producer {
3 use SQL::Translator::Constants qw(:sqlt_types);
4 use MooseX::Types::Moose qw(Bool HashRef Str);
5 use SQL::Translator::Types qw(Column Schema Table);
13 has 'no_comments' => (
27 has 'data_type_mapping' => (
33 method _build_data_type_mapping {
35 SQL_LONGVARCHAR() => 'text',
36 SQL_TIMESTAMP() => 'timestamp',
37 SQL_TYPE_TIMESTAMP() => 'timestamp without time zone',
38 SQL_TYPE_TIMESTAMP_WITH_TIMEZONE() => 'timestamp',
39 SQL_INTEGER() => 'integer',
41 SQL_VARCHAR() => 'varchar',
42 SQL_BIGINT() => 'bigint',
43 SQL_FLOAT() => 'numeric',
48 my $schema = $self->schema;
50 $self->_create_table($_) for values %{$schema->tables};
53 method _create_table(Table $table) {
55 my $add_drop_table = 1;
56 my $sqlite_version = 0;
59 my (@column_defs, @index_defs, @constraint_defs);
61 $create_table .= 'DROP TABLE ' . $table->name . ";\n" if $add_drop_table;
62 $create_table .= 'CREATE TABLE ' . $table->name . " (\n";
64 push @column_defs, $self->_create_column($_) for values %{$table->columns};
65 $create_table .= join(",\n", map { ' ' . $_ } @column_defs ) . "\n)";
66 print $create_table . "\n";
69 method _create_column(Column $column) {
71 $column_def = $column->name . ' ' . $column->data_type;
72 $column_def .= '(' . $column->size . ')' if $column->size;
73 $column_def .= ' NOT NULL' unless $column->is_nullable;