FusqlFS/Backend/PgSQL/Table/Data.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 2 SCAR 11.0
CC
2
Cov
0%
get_primary_key
6.0
init
2.0
BEGIN
2.0
CRAP 3.0
1 use strict;
2 use 5.010;
3  
4 package FusqlFS::Backend::PgSQL::Table::Data;
5 use FusqlFS::Version;
6 our $VERSION = $FusqlFS::Version::VERSION;
7 use parent 'FusqlFS::Artifact::Table::Data';
8  
9 use FusqlFS::Backend::PgSQL::Table::Struct;
10  
11 sub init
12 {
13 my $self = shift;
14 $self->SUPER::init();
15  
16 $self->{get_primary_expr} = $self->expr("SELECT indkey FROM pg_catalog.pg_index
17 WHERE indisprimary AND indrelid = (SELECT oid FROM pg_catalog.pg_class as c WHERE c.relname = ? AND relkind = 'r')");
18 }
19  
20 =begin testing list
21  
22 cmp_set $_tobj->list('fusqlfs_table'), [];
23  
24 =end testing
25 =cut
26  
27 =begin testing get
28  
29 is $_tobj->get('fusqlfs_table', '1'), undef;
30  
31 =end testing
32 =cut
33  
34 =begin testing drop after rename
35  
36 isnt $_tobj->drop('fusqlfs_table', '2'), undef;
37 is $_tobj->get('fusqlfs_table', '2'), undef;
38 is_deeply $_tobj->list('fusqlfs_table'), [];
39  
40 =end testing
41 =cut
42  
43 =begin testing create after get list
44  
45 ok $_tobj->create('fusqlfs_table', '1');
46 is_deeply $_tobj->get('fusqlfs_table', '1'), { id => 1 };
47 is_deeply $_tobj->list('fusqlfs_table'), [ 1 ];
48  
49 =end testing
50 =cut
51  
52 =begin testing rename after create
53  
54 isnt $_tobj->rename('fusqlfs_table', '1', '2'), undef;
55 is $_tobj->get('fusqlfs_table', '1'), undef;
56 is_deeply $_tobj->get('fusqlfs_table', '2'), { id => 2 };
57 is_deeply $_tobj->list('fusqlfs_table'), [ 2 ];
58  
59 =end testing
60 =cut
61  
62 sub get_primary_key
63 {
64 my $self = shift;
65 my ($table) = @_;
66 my @result = ();
67 my $data = $self->all_col($self->{get_primary_expr}, $table);
68 if ($data)
69 {
70 my $fields = FusqlFS::Backend::PgSQL::Table::Struct->new()->list($table);
71 @result = map { $fields->[$_-1] } split / /, $data->[0];
72 }
73 return @result;
74 }
75  
76 1;
77  
78 __END__