release 0.11017
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Generator / DDL / SQLite.pm
CommitLineData
a1552a5a 1package SQL::Translator::Generator::DDL::SQLite;
2
22c0c10f 3=head1 NAME
d22073f1 4
22c0c10f 5SQL::Translator::Generator::DDL::SQLite - A Moo based SQLite DDL generation
6engine.
7
8=head1 DESCRIPTION
9
10I<documentation volunteers needed>
11
12=cut
a1552a5a 13use Moo;
a1552a5a 14
2d23c1e1 15has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } );
16
39bfaa8b 17with 'SQL::Translator::Generator::Role::Quote';
a1552a5a 18with 'SQL::Translator::Generator::Role::DDL';
19
39bfaa8b 20sub name_sep { q(.) }
a1552a5a 21
22sub _build_type_map {
23 +{
8224e2cf 24 set => 'varchar',
25 bytea => 'blob',
a1552a5a 26 }
27}
28
8224e2cf 29sub _build_sizeless_types {
30 +{
31 text => 1,
32 blob => 1,
33 }
34}
27f0e868 35sub _build_numeric_types {
36 +{
37 int => 1,
38 integer => 1,
39 tinyint => 1,
40 smallint => 1,
41 mediumint => 1,
42 bigint => 1,
43 'unsigned big int' => 1,
44 int2 => 1,
45 int8 => 1,
46 numeric => 1,
47 decimal => 1,
48 boolean => 1,
49 real => 1,
50 double => 1,
51 'double precision' => 1,
52 float => 1,
53 }
54}
a1552a5a 55
56sub _build_unquoted_defaults {
57 +{
58 NULL => 1,
59 'now()' => 1,
60 CURRENT_TIMESTAMP => 1,
61 }
62}
63
64sub nullable { () }
65
27df230e 66sub _ipk {
67 my ($self, $field) = @_;
68
69 my $pk = $field->table->primary_key;
70 my @pk_fields = $pk ? $pk->fields : ();
71
72 $field->is_primary_key && scalar @pk_fields == 1 &&
73 ( $field->data_type =~ /int(eger)?$/i
74 ||
75 ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) )
76}
77
a1552a5a 78sub field {
79 my ($self, $field) = @_;
80
81 return join ' ',
82 $self->field_comments($field),
83 $self->field_name($field),
27df230e 84 ( $self->_ipk($field)
03b0fa25 85 ? $field->is_auto_increment
86 ? ( 'INTEGER PRIMARY KEY AUTOINCREMENT' )
87 : ( 'INTEGER PRIMARY KEY' )
a1552a5a 88 : ( $self->field_type($field) )
89 ),
90 $self->field_nullable($field),
ff6dc6d4 91 $self->field_default($field, {
92 NULL => 1,
93 'now()' => 1,
94 'CURRENT_TIMESTAMP' => 1,
95 }),
a1552a5a 96}
97
a1552a5a 981;
99
22c0c10f 100=head1 AUTHORS
101
102See the included AUTHORS file:
103L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>
104
105=head1 COPYRIGHT
106
107Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.
108
109=head1 LICENSE
110
111This code is free software and may be distributed under the same terms as Perl
112itself.
113
114=cut