From: Arthur Axel 'fREW' Schmidt Date: Tue, 8 Mar 2011 02:19:03 +0000 (-0600) Subject: initial SQLite Producer object X-Git-Tag: v0.11011~27^2~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a1552a5afba4d4780cc81e485bf263dca4a341c6;p=dbsrgits%2FSQL-Translator.git initial SQLite Producer object --- diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm new file mode 100644 index 0000000..fa60d9a --- /dev/null +++ b/lib/SQL/Translator/Generator/DDL/SQLite.pm @@ -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; +