make sure columns is an ARRAYREF
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Parser / DDL.pm
index 8e8c2ad..91fb07b 100644 (file)
@@ -1,6 +1,54 @@
-package SQL::Translator::Parser::DDL;
-use Moose::Role;
+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;
 
-no Moose::Role;
+    has 'data_type_mapping' => (
+        isa => HashRef,
+        is => 'ro',
+        lazy_build => 1
+    );
 
-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()
+        }
+    }
+}