From: Justin Hunter Date: Sat, 22 Aug 2009 21:42:21 +0000 (-0700) Subject: add base functionality to DDL parser X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9b50af5cf56964345bf3146d39b787f08376e142;p=dbsrgits%2FSQL-Translator-2.0-ish.git add base functionality to DDL parser --- diff --git a/lib/SQL/Translator/Parser/DDL.pm b/lib/SQL/Translator/Parser/DDL.pm index 4c48910..91fb07b 100644 --- a/lib/SQL/Translator/Parser/DDL.pm +++ b/lib/SQL/Translator/Parser/DDL.pm @@ -1,3 +1,54 @@ use MooseX::Declare; role SQL::Translator::Parser::DDL { + use MooseX::Types::Moose qw(HashRef Maybe Str); + use SQL::Translator::Types qw(Schema); + use SQL::Translator::Constants qw(:sqlt_types); + use MooseX::MultiMethods; + use Parse::RecDescent; + + has 'data_type_mapping' => ( + isa => HashRef, + is => 'ro', + lazy_build => 1 + ); + + has 'schema_name' => ( + is => 'rw', + isa => Maybe[Str], + lazy => 1, + default => undef + ); + + has 'grammar' => ( + is => 'ro', + isa => Str, + lazy_build => 1 + ); + + method _subclass { + return unless $self->type; + + my $grammar = 'SQL::Translator::Grammar::' . $self->type; + Class::MOP::load_class($grammar); + $grammar->meta->apply($self); + + my $role = __PACKAGE__ . '::' . $self->type; + Class::MOP::load_class($role); + $role->meta->apply($self); + } + + method _build_data_type_mapping { + return { + 'text' => SQL_LONGVARCHAR(), + 'timestamp' => SQL_TIMESTAMP(), + 'timestamp without time zone' => SQL_TYPE_TIMESTAMP(), + 'timestamp' => SQL_TYPE_TIMESTAMP_WITH_TIMEZONE(), + 'int' => SQL_INTEGER(), + 'integer' => SQL_INTEGER(), + 'character' => SQL_CHAR(), + 'varchar' => SQL_VARCHAR(), + 'char' => SQL_CHAR(), + 'bigint' => SQL_BIGINT() + } + } }