This seems to no longer be used anywhere...?
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Generator / DDL / SQLite.pm
CommitLineData
a1552a5a 1package SQL::Translator::Generator::DDL::SQLite;
2
d22073f1 3# AUTHOR: Arthur Axel fREW Schmidt
4# Copyright: Same as Perl 5
5
a1552a5a 6use Moo;
a1552a5a 7
2d23c1e1 8has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } );
9
39bfaa8b 10with 'SQL::Translator::Generator::Role::Quote';
a1552a5a 11with 'SQL::Translator::Generator::Role::DDL';
12
39bfaa8b 13sub name_sep { q(.) }
a1552a5a 14
15sub _build_type_map {
16 +{
8224e2cf 17 set => 'varchar',
18 bytea => 'blob',
a1552a5a 19 }
20}
21
8224e2cf 22sub _build_sizeless_types {
23 +{
24 text => 1,
25 blob => 1,
26 }
27}
27f0e868 28sub _build_numeric_types {
29 +{
30 int => 1,
31 integer => 1,
32 tinyint => 1,
33 smallint => 1,
34 mediumint => 1,
35 bigint => 1,
36 'unsigned big int' => 1,
37 int2 => 1,
38 int8 => 1,
39 numeric => 1,
40 decimal => 1,
41 boolean => 1,
42 real => 1,
43 double => 1,
44 'double precision' => 1,
45 float => 1,
46 }
47}
a1552a5a 48
49sub _build_unquoted_defaults {
50 +{
51 NULL => 1,
52 'now()' => 1,
53 CURRENT_TIMESTAMP => 1,
54 }
55}
56
57sub nullable { () }
58
27df230e 59sub _ipk {
60 my ($self, $field) = @_;
61
62 my $pk = $field->table->primary_key;
63 my @pk_fields = $pk ? $pk->fields : ();
64
65 $field->is_primary_key && scalar @pk_fields == 1 &&
66 ( $field->data_type =~ /int(eger)?$/i
67 ||
68 ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) )
69}
70
a1552a5a 71sub field {
72 my ($self, $field) = @_;
73
27df230e 74
a1552a5a 75 return join ' ',
76 $self->field_comments($field),
77 $self->field_name($field),
27df230e 78 ( $self->_ipk($field)
a1552a5a 79 ? ( 'INTEGER PRIMARY KEY' )
80 : ( $self->field_type($field) )
81 ),
82 $self->field_nullable($field),
ff6dc6d4 83 $self->field_default($field, {
84 NULL => 1,
85 'now()' => 1,
86 'CURRENT_TIMESTAMP' => 1,
87 }),
a1552a5a 88}
89
a1552a5a 901;
91