Commit | Line | Data |
a1552a5a |
1 | package SQL::Translator::Generator::DDL::SQLite; |
2 | |
22c0c10f |
3 | =head1 NAME |
d22073f1 |
4 | |
22c0c10f |
5 | SQL::Translator::Generator::DDL::SQLite - A Moo based SQLite DDL generation |
6 | engine. |
7 | |
8 | =head1 DESCRIPTION |
9 | |
10 | I<documentation volunteers needed> |
11 | |
12 | =cut |
a1552a5a |
13 | use Moo; |
a1552a5a |
14 | |
2d23c1e1 |
15 | has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } ); |
16 | |
39bfaa8b |
17 | with 'SQL::Translator::Generator::Role::Quote'; |
a1552a5a |
18 | with 'SQL::Translator::Generator::Role::DDL'; |
19 | |
39bfaa8b |
20 | sub name_sep { q(.) } |
a1552a5a |
21 | |
22 | sub _build_type_map { |
23 | +{ |
8224e2cf |
24 | set => 'varchar', |
25 | bytea => 'blob', |
a1552a5a |
26 | } |
27 | } |
28 | |
8224e2cf |
29 | sub _build_sizeless_types { |
30 | +{ |
31 | text => 1, |
32 | blob => 1, |
33 | } |
34 | } |
27f0e868 |
35 | sub _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 | |
56 | sub _build_unquoted_defaults { |
57 | +{ |
58 | NULL => 1, |
59 | 'now()' => 1, |
60 | CURRENT_TIMESTAMP => 1, |
61 | } |
62 | } |
63 | |
64 | sub nullable { () } |
65 | |
27df230e |
66 | sub _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 |
78 | sub field { |
79 | my ($self, $field) = @_; |
80 | |
27df230e |
81 | |
a1552a5a |
82 | return join ' ', |
83 | $self->field_comments($field), |
84 | $self->field_name($field), |
27df230e |
85 | ( $self->_ipk($field) |
a1552a5a |
86 | ? ( 'INTEGER PRIMARY KEY' ) |
87 | : ( $self->field_type($field) ) |
88 | ), |
89 | $self->field_nullable($field), |
ff6dc6d4 |
90 | $self->field_default($field, { |
91 | NULL => 1, |
92 | 'now()' => 1, |
93 | 'CURRENT_TIMESTAMP' => 1, |
94 | }), |
a1552a5a |
95 | } |
96 | |
a1552a5a |
97 | 1; |
98 | |
22c0c10f |
99 | =head1 AUTHORS |
100 | |
101 | See the included AUTHORS file: |
102 | L<http://search.cpan.org/dist/SQL-Translator/AUTHORS> |
103 | |
104 | =head1 COPYRIGHT |
105 | |
106 | Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above. |
107 | |
108 | =head1 LICENSE |
109 | |
110 | This code is free software and may be distributed under the same terms as Perl |
111 | itself. |
112 | |
113 | =cut |