« blib/lib/SQL/Translator/Parser/Oracle.pm
↑ Summary
blib/lib/SQL/Translator/Generator/DDL/SQLServer.pm »
| 1 | package SQL::Translator::Parser::YAML; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 16 | our $VERSION = '1.63'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 16 | ▶ | use SQL::Translator::Schema; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 16 | ▶ | use SQL::Translator::Utils qw(header_comment); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 16 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 16 | ▶ | use YAML qw(Load); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | sub parse { | ||||||||||||||
| 13 | 24 | ▶ | my ($translator, $data) = @_; | ||||||||||||
|
Subroutine
parse: called CC=23 SCAR=33.9
Pod
undocumented
| |||||||||||||||
| 14 | 24 | $data = Load($data); | |||||||||||||
| 15 | 24 | $data = $data->{'schema'}; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 24 | ▶ | warn "YAML data:",Dumper( $data ) if $translator->debug; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 24 | my $schema = $translator->schema; | |||||||||||||
| 20 | |||||||||||||||
| 21 | # | ||||||||||||||
| 22 | # Tables | ||||||||||||||
| 23 | # | ||||||||||||||
| 24 | my @tables = | ||||||||||||||
| 25 | 63 | map { $data->{'tables'}{ $_->[1] } } | |||||||||||||
| 26 | 59 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 27 | 63 | ▶ | map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] } | ||||||||||||
|
Condition100%2/2
$data->{'tables'}{$_}{'order'} || 0
MC/DC100%1/1
$data->{'tables'}{$_}{'order'} || 0
$data->{'tables'}{$_}{'order'}
Truth table100%2/2
A
A= $data->{'tables'}{$_}{'order'}
| |||||||||||||||
| 28 | 24 | keys %{ $data->{'tables'} } | |||||||||||||
| 29 | ; | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 24 | for my $tdata ( @tables ) { | |||||||||||||
| 32 | |||||||||||||||
| 33 | my $table = $schema->add_table( | ||||||||||||||
| 34 | map { | ||||||||||||||
| 35 | 63 | ▶ | $tdata->{$_} ? ($_ => $tdata->{$_}) : () | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | } (qw/name extra options/) | ||||||||||||||
| 37 | ) or die $schema->error; | ||||||||||||||
| 38 | |||||||||||||||
| 39 | my @fields = | ||||||||||||||
| 40 | 196 | map { $tdata->{'fields'}{ $_->[1] } } | |||||||||||||
| 41 | 262 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 42 | 196 | map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] } | |||||||||||||
| 43 | 63 | keys %{ $tdata->{'fields'} } | |||||||||||||
| 44 | ; | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 63 | for my $fdata ( @fields ) { | |||||||||||||
| 47 | 196 | ▶ | $table->add_field( %$fdata ) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | $table->primary_key( $fdata->{'name'} ) | ||||||||||||||
| 49 | 196 | ▶ | if $fdata->{'is_primary_key'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 63 | ▶ | for my $idata ( @{ $tdata->{'indices'} || [] } ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 19 | ▶ | $table->add_index( %$idata ) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 63 | ▶ | for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 81 | ▶ | $table->add_constraint( %$cdata ) or die $table->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | } | ||||||||||||||
| 59 | |||||||||||||||
| 60 | $table->comments( $tdata->{'comments' } ) | ||||||||||||||
| 61 | 63 | ▶ | if exists $tdata->{'comments'}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | # | ||||||||||||||
| 65 | # Views | ||||||||||||||
| 66 | # | ||||||||||||||
| 67 | my @views = | ||||||||||||||
| 68 | 3 | map { $data->{'views'}{ $_->[1] } } | |||||||||||||
| 69 | 0 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 70 | 3 | map { [ $data->{'views'}{ $_ }{'order'}, $_ ] } | |||||||||||||
| 71 | 24 | keys %{ $data->{'views'} } | |||||||||||||
| 72 | ; | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 24 | for my $vdata ( @views ) { | |||||||||||||
| 75 | 3 | ▶ | $schema->add_view( %$vdata ) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | # | ||||||||||||||
| 79 | # Triggers | ||||||||||||||
| 80 | # | ||||||||||||||
| 81 | my @triggers = | ||||||||||||||
| 82 | 9 | map { $data->{'triggers'}{ $_->[1] } } | |||||||||||||
| 83 | 9 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 84 | 9 | map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] } | |||||||||||||
| 85 | 24 | keys %{ $data->{'triggers'} } | |||||||||||||
| 86 | ; | ||||||||||||||
| 87 | |||||||||||||||
| 88 | 24 | for my $tdata ( @triggers ) { | |||||||||||||
| 89 | 9 | ▶ | $schema->add_trigger( %$tdata ) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | # | ||||||||||||||
| 93 | # Procedures | ||||||||||||||
| 94 | # | ||||||||||||||
| 95 | my @procedures = | ||||||||||||||
| 96 | 3 | map { $data->{'procedures'}{ $_->[1] } } | |||||||||||||
| 97 | 0 | sort { $a->[0] <=> $b->[0] } | |||||||||||||
| 98 | 3 | map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] } | |||||||||||||
| 99 | 24 | keys %{ $data->{'procedures'} } | |||||||||||||
| 100 | ; | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 24 | for my $tdata ( @procedures ) { | |||||||||||||
| 103 | 3 | ▶ | $schema->add_procedure( %$tdata ) or die $schema->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 24 | ▶ | if ( my $tr_data = $data->{'translator'} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 107 | 0 | $translator->add_drop_table( $tr_data->{'add_drop_table'} ); | |||||||||||||
| 108 | 0 | $translator->filename( $tr_data->{'filename'} ); | |||||||||||||
| 109 | 0 | $translator->no_comments( $tr_data->{'no_comments'} ); | |||||||||||||
| 110 | 0 | $translator->parser_args( $tr_data->{'parser_args'} ); | |||||||||||||
| 111 | 0 | $translator->producer_args( $tr_data->{'producer_args'} ); | |||||||||||||
| 112 | 0 | $translator->parser_type( $tr_data->{'parser_type'} ); | |||||||||||||
| 113 | 0 | $translator->producer_type( $tr_data->{'producer_type'} ); | |||||||||||||
| 114 | 0 | $translator->show_warnings( $tr_data->{'show_warnings'} ); | |||||||||||||
| 115 | 0 | $translator->trace( $tr_data->{'trace'} ); | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 24 | return 1; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 16 | 1; | |||||||||||||
| 122 | |||||||||||||||
| 123 | __END__ | ||||||||||||||