File: SQLite.pm

package info (click to toggle)
libsql-translator-perl 0.11011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,380 kB
  • sloc: perl: 251,748; sql: 3,805; xml: 233; makefile: 7
file content (113 lines) | stat: -rw-r--r-- 2,265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package SQL::Translator::Generator::DDL::SQLite;

=head1 NAME

SQL::Translator::Generator::DDL::SQLite - A Moo based SQLite DDL generation
engine.

=head1 DESCRIPTION

I<documentation volunteers needed>

=cut
use Moo;

has quote_chars => (is=>'ro', default=>sub { +[qw(" ")] } );

with 'SQL::Translator::Generator::Role::Quote';
with 'SQL::Translator::Generator::Role::DDL';

sub name_sep { q(.) }

sub _build_type_map {
   +{
      set   => 'varchar',
      bytea => 'blob',
   }
}

sub _build_sizeless_types {
   +{
      text => 1,
      blob => 1,
   }
}
sub _build_numeric_types {
   +{
      int                => 1,
      integer            => 1,
      tinyint            => 1,
      smallint           => 1,
      mediumint          => 1,
      bigint             => 1,
      'unsigned big int' => 1,
      int2               => 1,
      int8               => 1,
      numeric            => 1,
      decimal            => 1,
      boolean            => 1,
      real               => 1,
      double             => 1,
      'double precision' => 1,
      float              => 1,
   }
}

sub _build_unquoted_defaults {
   +{
       NULL              => 1,
       'now()'           => 1,
       CURRENT_TIMESTAMP => 1,
   }
}

sub nullable { () }

sub _ipk {
   my ($self, $field) = @_;

   my $pk = $field->table->primary_key;
   my @pk_fields = $pk ? $pk->fields : ();

   $field->is_primary_key && scalar @pk_fields == 1 &&
   ( $field->data_type =~ /int(eger)?$/i
    ||
   ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) )
}

sub field {
   my ($self, $field) = @_;


   return join ' ',
      $self->field_comments($field),
      $self->field_name($field),
      ( $self->_ipk($field)
         ? ( 'INTEGER PRIMARY KEY' )
         : ( $self->field_type($field) )
      ),
      $self->field_nullable($field),
      $self->field_default($field, {
         NULL => 1,
         'now()' => 1,
         'CURRENT_TIMESTAMP' => 1,
      }),
}

1;

=head1 AUTHORS

See the included AUTHORS file:
L<http://search.cpan.org/dist/SQL-Translator/AUTHORS>

=head1 COPYRIGHT

Copyright (c) 2012 the SQL::Translator L</AUTHORS> as listed above.

=head1 LICENSE

This code is free software and may be distributed under the same terms as Perl
itself.

=cut