| 1 | package Type::Guess::Role::SQL::Pg; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | sub to_sql { | ||||||||||||||||||||||||||
|
Subroutine
to_sql: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 6 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 7 | 13 | ▶ | my $type = ref $self->type ? $self->type->name : $self->type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | return $self->integer_chars > 9 ? "BIGINT" : "INTEGER" if $type eq "Int"; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | return "TIMESTAMP" if $self->type eq 'DateTime'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | return sprintf "DECIMAL(%d,%d)", $self->length, $self->precision if $type eq "Num"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | return sprintf "VARCHAR(%d)", $self->length if $type eq "Str" && $self->length < 1024; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "Str" and $self->length < 1024
MC/DC50%1/2
$type eq "Str" and $self->length < 1024
$type eq "Str"
$self->length < 1024
Truth table66%2/3
A and B
A= $type eq "Str"B= $self->length < 1024
| |||||||||||||||||||||||||||||
| 13 | 1 | return "TEXT"; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | 1; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 TIMESTAMP | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Postgres distinguishes TIMESTAMP (no timezone) and TIMESTAMP WITH TIME ZONE. | ||||||||||||||||||||||||||||
| 22 | Type::Guess emits TIMESTAMP by default. If your application is timezone-aware, | ||||||||||||||||||||||||||||
| 23 | cast manually or compose a role that overrides to_sql for DateTime to return | ||||||||||||||||||||||||||||
| 24 | TIMESTAMP WITH TIME ZONE. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||