File Coverage

blib/lib/SQL/Translator/Generator/DDL/SQLite.pm
Criterion Covered Total %
statement 16 17 94.1
branch 8 8 100.0
condition 9 15 60.0
subroutine 9 10 90.0
pod 0 4 0.0
total 42 54 77.7


line stmt bran cond sub pod time code
1             package SQL::Translator::Generator::DDL::SQLite;
2              
3             =head1 NAME
4              
5             SQL::Translator::Generator::DDL::SQLite - A Moo based SQLite DDL generation
6             engine.
7              
8             =head1 DESCRIPTION
9              
10             I
11              
12             =cut
13              
14 8     8   59 use Moo;
  8         32  
  8         66  
15              
16             has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } );
17              
18             with 'SQL::Translator::Generator::Role::Quote';
19             with 'SQL::Translator::Generator::Role::DDL';
20              
21 115     115 0 321 sub name_sep { q(.) }
22              
23             sub _build_type_map {
24             +{
25 7     7   189 set => 'varchar',
26             bytea => 'blob',
27             }
28             }
29              
30             sub _build_sizeless_types {
31             +{
32 7     7   487 text => 1,
33             blob => 1,
34             }
35             }
36             sub _build_numeric_types {
37             +{
38 4     4   172 int => 1,
39             integer => 1,
40             tinyint => 1,
41             smallint => 1,
42             mediumint => 1,
43             bigint => 1,
44             'unsigned big int' => 1,
45             int2 => 1,
46             int8 => 1,
47             numeric => 1,
48             decimal => 1,
49             boolean => 1,
50             real => 1,
51             double => 1,
52             'double precision' => 1,
53             float => 1,
54             }
55             }
56              
57             sub _build_unquoted_defaults {
58             +{
59 0     0   0 NULL => 1,
60             'now()' => 1,
61             CURRENT_TIMESTAMP => 1,
62             }
63             }
64              
65 55     55 0 1745 sub nullable { () }
66              
67             sub _ipk {
68 87     87   204 my ($self, $field) = @_;
69              
70 87         1718 my $pk = $field->table->primary_key;
71 87 100       1754 my @pk_fields = $pk ? $pk->fields : ();
72              
73 87 100 0     1565 $field->is_primary_key && scalar @pk_fields == 1 &&
      33        
      100        
74             ( $field->data_type =~ /int(eger)?$/i
75             ||
76             ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) )
77             }
78              
79             sub field_autoinc {
80 86     86 0 1315 my ($self, $field) = @_;
81              
82             return (
83             (
84 86 100 66     1672 ($field->extra->{auto_increment_type}||'') eq 'monotonic'
85             and
86             $self->_ipk($field)
87             and
88             $field->is_auto_increment
89             )
90             ? 'AUTOINCREMENT'
91             : ''
92             );
93             }
94              
95             sub field {
96 86     86 0 192 my ($self, $field) = @_;
97              
98              
99 86 100 100     257 return join ' ',
100             $self->field_comments($field),
101             $self->field_name($field),
102             ( $self->_ipk($field)
103             ? ( 'INTEGER PRIMARY KEY' )
104             : ( $self->field_type($field) )
105             ),
106             ( $self->field_autoinc($field) || () ),
107             $self->field_nullable($field),
108             $self->field_default($field, {
109             NULL => 1,
110             'now()' => 1,
111             'CURRENT_TIMESTAMP' => 1,
112             }),
113             }
114              
115             1;
116              
117             =head1 AUTHORS
118              
119             See the included AUTHORS file:
120             L
121              
122             =head1 COPYRIGHT
123              
124             Copyright (c) 2012 the SQL::Translator L as listed above.
125              
126             =head1 LICENSE
127              
128             This code is free software and may be distributed under the same terms as Perl
129             itself.
130              
131             =cut