use MooseX::Declare;
class SQL::Translator::Producer {
- use MooseX::Types::Moose qw(Bool Str);
+ use SQL::Translator::Constants qw(:sqlt_types);
+ use MooseX::Types::Moose qw(Bool HashRef Str);
use SQL::Translator::Types qw(Column Schema Table);
has 'schema' => (
lazy => 1,
default => 1
);
-
+
+ has 'data_type_mapping' => (
+ isa => HashRef,
+ is => 'ro',
+ lazy_build => 1
+ );
+
+ method _build_data_type_mapping {
+ return {
+ SQL_LONGVARCHAR() => 'text',
+ SQL_TIMESTAMP() => 'timestamp',
+ SQL_TYPE_TIMESTAMP() => 'timestamp without time zone',
+ SQL_TYPE_TIMESTAMP_WITH_TIMEZONE() => 'timestamp',
+ SQL_INTEGER() => 'integer',
+ SQL_CHAR() => 'character',
+ SQL_VARCHAR() => 'varchar',
+ SQL_BIGINT() => 'bigint',
+ SQL_FLOAT() => 'numeric',
+ };
+ }
+
method produce {
my $schema = $self->schema;
use SQL::Translator::Constants qw(:sqlt_types);
use SQL::Translator::Types qw(Column Index Table);
- my %data_type_mapping = (
- SQL_LONGVARCHAR() => 'text',
- SQL_TIMESTAMP() => 'timestamp',
- SQL_TYPE_TIMESTAMP() => 'timestamp without time zone',
- SQL_TYPE_TIMESTAMP_WITH_TIMEZONE() => 'timestamp',
- SQL_INTEGER() => 'integer',
- SQL_CHAR() => 'character',
- SQL_VARCHAR() => 'varchar',
- SQL_BIGINT() => 'bigint',
- SQL_FLOAT() => 'numeric',
- );
-
method _create_table(Table $table) {
my $pg_version = 0;
my $column_def;
$column_def = $column->name . ' ';
- $column_def .= defined $data_type_mapping{$column->data_type}
- ? $data_type_mapping{$column->data_type}
+ $column_def .= defined $self->data_type_mapping->{$column->data_type}
+ ? $self->data_type_mapping->{$column->data_type}
: $column->data_type;
$column_def .= '(' . $column->size . ')' if $size;
$column_def .= ' NOT NULL' unless $column->is_nullable;
role SQL::Translator::Producer::SQL::SQLite {
use SQL::Translator::Constants qw(:sqlt_types);
use SQL::Translator::Types qw(Column Table);
-
- my %data_type_mapping = (
- SQL_LONGVARCHAR() => 'text',
- SQL_TIMESTAMP() => 'timestamp',
- SQL_INTEGER() => 'integer',
- SQL_CHAR() => 'character',
- SQL_VARCHAR() => 'varchar',
- SQL_BIGINT() => 'integer',
- );
+
+ around _build_data_type_mapping {
+ my $data_type_mapping = $self->$orig;
+ $data_type_mapping->{SQL_FLOAT()} = 'real';
+ $data_type_mapping->{SQL_BIGINT()} = 'integer';
+
+ return $data_type_mapping;
+ };
method _create_table(Table $table) {
my $sqlite_version = 0;
my $column_def;
$column_def = $column->name . ' ';
- $column_def .= defined $data_type_mapping{$column->data_type}
- ? $data_type_mapping{$column->data_type}
+ $column_def .= defined $self->data_type_mapping->{$column->data_type}
+ ? $self->data_type_mapping->{$column->data_type}
: $column->data_type;
#$column_def .= '(' . $column->size . ')' if $size;
$column_def .= ' NOT NULL' unless $column->is_nullable;