initial SQLite Producer object
Arthur Axel 'fREW' Schmidt [Tue, 8 Mar 2011 02:19:03 +0000 (20:19 -0600)]
lib/SQL/Translator/Generator/DDL/SQLite.pm [new file with mode: 0644]

diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm
new file mode 100644 (file)
index 0000000..fa60d9a
--- /dev/null
@@ -0,0 +1,61 @@
+package SQL::Translator::Generator::DDL::SQLite;
+
+use Moo;
+use SQL::Translator::Generator::Utils;
+
+with 'SQL::Translator::Generator::Role::DDL';
+
+sub _build_shim { SQL::Translator::Generator::Utils->new( quote_chars => q(") ) }
+
+sub _build_type_map {
+   +{
+      date => 'datetime',
+      'time' => 'datetime',
+   }
+}
+
+has sizeless_types => (
+   is => 'ro',
+   builder => '_build_sizeless_types',
+);
+
+sub _build_sizeless_types { +{ text => 1 } }
+sub _build_numeric_types { +{ int => 1, tinyint => 1 } }
+
+sub _build_unquoted_defaults {
+   +{
+       NULL              => 1,
+       'now()'           => 1,
+       CURRENT_TIMESTAMP => 1,
+   }
+}
+
+sub nullable { () }
+
+sub field {
+   my ($self, $field) = @_;
+
+   return join ' ',
+      $self->field_comments($field),
+      $self->field_name($field),
+      ( $field->is_auto_increment
+         ? ( 'INTEGER PRIMARY KEY' )
+         : ( $self->field_type($field) )
+      ),
+      $self->field_nullable($field),
+      $self->field_default($field),
+}
+
+sub field_type_size {
+   my ($self, $field) = @_;
+
+   ($field->size && !$self->sizeless_types->{$field->data_type}
+      ? '(' . $field->size . ')'
+      : ''
+   )
+}
+
+sub field_autoinc { ( $_[1]->is_auto_increment ? 'IDENTITY' : () ) }
+
+1;
+