| 1 | package DBIO::PostgreSQL::Result; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: PostgreSQL-specific Result component for DBIO | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 28 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 28 | ▶ | use base 'DBIO::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 28 | ▶ | use DBIO::PostgreSQL::ResultSet (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use DBIO::PostgreSQL::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # karr k40: pgvector columns inflate/deflate by default. Loading the | ||||||||||||||||||||||||||||
| 15 | # InflateColumn::Vector component here makes declaring a vector/halfvec/ | ||||||||||||||||||||||||||||
| 16 | # sparsevec column the whole opt-in — the same way this class already | ||||||||||||||||||||||||||||
| 17 | # promotes resultset_class for those columns. Opt out per column with | ||||||||||||||||||||||||||||
| 18 | # inflate_pgvector => 0. | ||||||||||||||||||||||||||||
| 19 | 28 | __PACKAGE__->load_components('PostgreSQL::InflateColumn::Vector'); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # karr k65: tsvector columns inflate/deflate by default, same opt-in-by- | ||||||||||||||||||||||||||||
| 22 | # declaration model. Unlike Vector this carries no resultset_class promotion | ||||||||||||||||||||||||||||
| 23 | # (that is pgvector/nearest_neighbors-specific). Opt out per column with | ||||||||||||||||||||||||||||
| 24 | # inflate_tsvector => 0. | ||||||||||||||||||||||||||||
| 25 | 28 | __PACKAGE__->load_components('PostgreSQL::InflateColumn::TSVector'); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 28 | __PACKAGE__->mk_classdata('_pg_schema_name'); | |||||||||||||||||||||||||||
| 28 | 28 | __PACKAGE__->mk_classdata('_pg_indexes' => {}); | |||||||||||||||||||||||||||
| 29 | 28 | __PACKAGE__->mk_classdata('_pg_triggers' => {}); | |||||||||||||||||||||||||||
| 30 | 28 | __PACKAGE__->mk_classdata('_pg_rls'); | |||||||||||||||||||||||||||
| 31 | 28 | __PACKAGE__->mk_classdata('_pg_check_constraints' => {}); | |||||||||||||||||||||||||||
| 32 | 28 | __PACKAGE__->mk_classdata('_pg_extra_ddl' => []); | |||||||||||||||||||||||||||
| 33 | 28 | __PACKAGE__->mk_classdata('_pg_fk_constraints_from_rels' => 1); | |||||||||||||||||||||||||||
| 34 | 28 | __PACKAGE__->mk_classdata('_pg_unique_options' => {}); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 782 | ▶ | sub pg_schema { | ||||||||||||||||||||||||||
|
Subroutine
pg_schema: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 782 | my ($class, $name) = @_; | |||||||||||||||||||||||||||
| 40 | 782 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 15 | $class->_pg_schema_name($name); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 782 | return $class->_pg_schema_name; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 9 | ▶ | sub pg_qualified_table { | ||||||||||||||||||||||||||
|
Subroutine
pg_qualified_table: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 9 | my ($class) = @_; | |||||||||||||||||||||||||||
| 49 | 9 | my $schema = $class->_pg_schema_name; | |||||||||||||||||||||||||||
| 50 | 9 | my $table = $class->table; | |||||||||||||||||||||||||||
| 51 | 9 | ▶ | return DBIO::PostgreSQL::Util::quote_qualified( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | ($schema ? $schema : ()), $table, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 33 | ▶ | sub pg_index { | ||||||||||||||||||||||||||
|
Subroutine
pg_index: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 33 | my ($class, $name, $def) = @_; | |||||||||||||||||||||||||||
| 59 | 33 | ▶ | if ($def) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 33 | my $indexes = { %{ $class->_pg_indexes } }; | |||||||||||||||||||||||||||
| 61 | 33 | $indexes->{$name} = $def; | |||||||||||||||||||||||||||
| 62 | 33 | $class->_pg_indexes($indexes); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 33 | return $class->_pg_indexes->{$name}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 227 | ▶ | sub pg_indexes { | ||||||||||||||||||||||||||
|
Subroutine
pg_indexes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 227 | my ($class) = @_; | |||||||||||||||||||||||||||
| 70 | 227 | return { %{ $class->_pg_indexes } }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub pg_trigger { | ||||||||||||||||||||||||||
|
Subroutine
pg_trigger: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 5 | my ($class, $name, $def) = @_; | |||||||||||||||||||||||||||
| 76 | 5 | ▶ | if ($def) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 5 | my $triggers = { %{ $class->_pg_triggers } }; | |||||||||||||||||||||||||||
| 78 | 5 | $triggers->{$name} = $def; | |||||||||||||||||||||||||||
| 79 | 5 | $class->_pg_triggers($triggers); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 5 | return $class->_pg_triggers->{$name}; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 219 | ▶ | sub pg_triggers { | ||||||||||||||||||||||||||
|
Subroutine
pg_triggers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 219 | my ($class) = @_; | |||||||||||||||||||||||||||
| 87 | 219 | return { %{ $class->_pg_triggers } }; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 231 | ▶ | sub pg_rls { | ||||||||||||||||||||||||||
|
Subroutine
pg_rls: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 231 | my ($class, $def) = @_; | |||||||||||||||||||||||||||
| 93 | 231 | ▶ | if ($def) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 6 | $class->_pg_rls($def); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 231 | return $class->_pg_rls; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 5 | ▶ | sub pg_check_constraint { | ||||||||||||||||||||||||||
|
Subroutine
pg_check_constraint: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 5 | my ($class, $name, $def) = @_; | |||||||||||||||||||||||||||
| 102 | 5 | ▶ | if (defined $def) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 3 | ▶ | my $entry = ref $def eq 'HASH' ? { %$def } : { definition => $def }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | $entry->{constraint_name} //= $name; | ||||||||||||||||||||||||||
|
Condition66%2/3
$entry->{"constraint_name"} //= $name
MC/DC0%0/2
$entry->{"constraint_name"} //= $name
$entry->{"constraint_name"}
$name
Truth table66%2/3
A //= B
A= $entry->{"constraint_name"}B= $name
| |||||||||||||||||||||||||||||
| 105 | 3 | my $checks = { %{ $class->_pg_check_constraints } }; | |||||||||||||||||||||||||||
| 106 | 3 | $checks->{$name} = $entry; | |||||||||||||||||||||||||||
| 107 | 3 | $class->_pg_check_constraints($checks); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 5 | return $class->_pg_check_constraints->{$name}; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 219 | ▶ | sub pg_check_constraints { | ||||||||||||||||||||||||||
|
Subroutine
pg_check_constraints: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 219 | my ($class) = @_; | |||||||||||||||||||||||||||
| 115 | 219 | return { %{ $class->_pg_check_constraints } }; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 225 | ▶ | sub pg_extra_ddl { | ||||||||||||||||||||||||||
|
Subroutine
pg_extra_ddl: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 225 | my ($class, @stmts) = @_; | |||||||||||||||||||||||||||
| 121 | 225 | ▶ | if (@stmts) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 5 | ▶ | my @flat = map { ref eq 'ARRAY' ? @$_ : $_ } @stmts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 5 | my $cur = [ @{ $class->_pg_extra_ddl }, @flat ]; | |||||||||||||||||||||||||||
| 124 | 5 | $class->_pg_extra_ddl($cur); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 225 | return [ @{ $class->_pg_extra_ddl } ]; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 235 | ▶ | sub pg_unique_options { | ||||||||||||||||||||||||||
|
Subroutine
pg_unique_options: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 235 | my ($class, $name, $options) = @_; | |||||||||||||||||||||||||||
| 132 | 235 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 6 | ▶ | $class->throw_exception('pg_unique_options takes the name of a UNIQUE constraint and a hash of options') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $options and ref $options eq "HASH"
MC/DC0%0/2
defined $options and ref $options eq "HASH"
defined $options
ref $options eq "HASH"
Truth table33%1/3
A and B
A= defined $optionsB= ref $options eq "HASH"
| |||||||||||||||||||||||||||||
| 134 | unless defined $options && ref $options eq 'HASH'; | ||||||||||||||||||||||||||||
| 135 | 6 | $class->_pg_unique_options({ %{ $class->_pg_unique_options }, $name => { %$options } }); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 235 | return { map { $_ => { %{ $class->_pg_unique_options->{$_} } } } keys %{ $class->_pg_unique_options } }; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 304 | ▶ | sub pg_fk_constraints_from_rels { | ||||||||||||||||||||||||||
|
Subroutine
pg_fk_constraints_from_rels: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 304 | my ($class, $bool) = @_; | |||||||||||||||||||||||||||
| 143 | 304 | ▶ | if (defined $bool) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 63 | $class->_pg_fk_constraints_from_rels($bool); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 304 | return $class->_pg_fk_constraints_from_rels; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 518 | ▶ | sub register_column { | ||||||||||||||||||||||||||
|
Subroutine
register_column: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 518 | my ($class, $column, $info, @rest) = @_; | |||||||||||||||||||||||||||
| 152 | 518 | $class->next::method($column, $info, @rest); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # Single pgvector-type detection site: reuse the shared helper from the | ||||||||||||||||||||||||||||
| 155 | # InflateColumn::Vector component (loaded above), so promotion and inflation | ||||||||||||||||||||||||||||
| 156 | # share one regex with identical whitespace tolerance (karr k61). | ||||||||||||||||||||||||||||
| 157 | 518 | my ($type) = $class->_pgvector_type_info($info->{data_type}); | |||||||||||||||||||||||||||
| 158 | 518 | ▶ | return unless $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 23 | my $rs_class = $class->resultset_class; | |||||||||||||||||||||||||||
| 161 | 23 | ▶ | $class->resultset_class('DBIO::PostgreSQL::ResultSet') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$rs_class and not $rs_class->isa("DBIO::PostgreSQL::ResultSet")
MC/DC50%1/2
$rs_class and not $rs_class->isa("DBIO::PostgreSQL::ResultSet")
$rs_class
not $rs_class->isa("DBIO::PostgreSQL::ResultSet")
Truth table66%2/3
A and not(B)
A= $rs_classB= not $rs_class->isa("DBIO::PostgreSQL::ResultSet")
| |||||||||||||||||||||||||||||
| 162 | if $rs_class && !$rs_class->isa('DBIO::PostgreSQL::ResultSet'); | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 23 | return; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 28 | 1; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||