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 10     10   97 use Moo;
  10         23  
  10         89  
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 182     182 0 658 sub name_sep {q(.)}
22              
23             sub _build_type_map {
24             +{
25 9     9   221 set => 'varchar',
26             bytea => 'blob',
27             };
28             }
29              
30             sub _build_sizeless_types {
31             +{
32 9     9   647 text => 1,
33             blob => 1,
34             };
35             }
36              
37             sub _build_numeric_types {
38             +{
39 5     5   207 int => 1,
40             integer => 1,
41             tinyint => 1,
42             smallint => 1,
43             mediumint => 1,
44             bigint => 1,
45             'unsigned big int' => 1,
46             int2 => 1,
47             int8 => 1,
48             numeric => 1,
49             decimal => 1,
50             boolean => 1,
51             real => 1,
52             double => 1,
53             'double precision' => 1,
54             float => 1,
55             };
56             }
57              
58             sub _build_unquoted_defaults {
59             +{
60 0     0   0 NULL => 1,
61             'now()' => 1,
62             CURRENT_TIMESTAMP => 1,
63             };
64             }
65              
66 73     73 0 2775 sub nullable { () }
67              
68             sub _ipk {
69 115     115   275 my ($self, $field) = @_;
70              
71 115         6253 my $pk = $field->table->primary_key;
72 115 100       3100 my @pk_fields = $pk ? $pk->fields : ();
73              
74 115 100 0     2553 $field->is_primary_key
      33        
      100        
75             && scalar @pk_fields == 1
76             && ($field->data_type =~ /int(eger)?$/i
77             || ($field->data_type =~ /^number?$/i && $field->size !~ /,/));
78             }
79              
80             sub field_autoinc {
81 112     112 0 2052 my ($self, $field) = @_;
82              
83             return (
84             (
85 112 100 66     2756 ($field->extra->{auto_increment_type} || '') eq 'monotonic'
86             and $self->_ipk($field)
87             and $field->is_auto_increment
88             )
89             ? 'AUTOINCREMENT'
90             : ''
91             );
92             }
93              
94             sub field {
95 112     112 0 259 my ($self, $field) = @_;
96              
97 112 100 100     408 return join ' ', $self->field_comments($field), $self->field_name($field),
98             (
99             $self->_ipk($field)
100             ? ('INTEGER PRIMARY KEY')
101             : ($self->field_type($field))
102             ),
103             ($self->field_autoinc($field) || ()), $self->field_nullable($field),
104             $self->field_default(
105             $field,
106             {
107             NULL => 1,
108             'now()' => 1,
109             'CURRENT_TIMESTAMP' => 1,
110             }
111             ),
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