| 1 | package Geoffrey::Converter::Pg::Index; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use 5.016; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | $Geoffrey::Converter::Pg::Index::VERSION = '0.000201'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | sub add { | ||||||||||
| 13 | 0 | ▶ | my ( $self, $params ) = @_; | ||||||||
|
Subroutine
add: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 14 | 0 | ▶ | if ( !$params ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 0 | require Geoffrey::Exception::General; | |||||||||
| 16 | 0 | Geoffrey::Exception::General::throw_no_params(); | |||||||||
| 17 | } | ||||||||||
| 18 | 0 | ▶ | if ( !$params->{table} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | require Geoffrey::Exception::RequiredValue; | |||||||||
| 20 | 0 | Geoffrey::Exception::RequiredValue::throw_table_name(); | |||||||||
| 21 | } | ||||||||||
| 22 | 0 | ▶ | if ( !$params->{column} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | require Geoffrey::Exception::RequiredValue; | |||||||||
| 24 | 0 | Geoffrey::Exception::RequiredValue::throw_refcolumn_missing(); | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | require Ref::Util; | |||||||||
| 27 | 0 | require Geoffrey::Utils; | |||||||||
| 28 | return Geoffrey::Utils::replace_spare( | ||||||||||
| 29 | q~CREATE INDEX {0} ON {1} ({2})~, | ||||||||||
| 30 | [ | ||||||||||
| 31 | Geoffrey::Utils::add_name( | ||||||||||
| 32 | { | ||||||||||
| 33 | prefix => 'ix', | ||||||||||
| 34 | name => $params->{name}, | ||||||||||
| 35 | context => $params->{table} | ||||||||||
| 36 | } | ||||||||||
| 37 | ), | ||||||||||
| 38 | $params->{table}, | ||||||||||
| 39 | ( | ||||||||||
| 40 | join ', ', Ref::Util::is_arrayref( $params->{column} ) | ||||||||||
| 41 | 0 | ? @{ $params->{column} } | |||||||||
| 42 | : ( $params->{column} ) | ||||||||||
| 43 | 0 | ▶ | ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | ] | ||||||||||
| 45 | ); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | sub drop { | ||||||||||
| 49 | 0 | ▶ | my ( $self, $name ) = @_; | ||||||||
|
Subroutine
drop: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 50 | 0 | ▶ | if ( !$name ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | require Geoffrey::Exception::RequiredValue; | |||||||||
| 52 | 0 | Geoffrey::Exception::RequiredValue::throw_index_name(); | |||||||||
| 53 | } | ||||||||||
| 54 | 0 | return qq~DROP INDEX $name~; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | sub list { | ||||||||||
| 58 | 0 | ▶ | my ( $self, $schema ) = @_; | ||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 59 | 0 | require Geoffrey::Utils; | |||||||||
| 60 | 0 | return q~SELECT | |||||||||
| 61 | U.usename AS user_name, | ||||||||||
| 62 | ns.nspname AS schema_name, | ||||||||||
| 63 | idx.indrelid :: REGCLASS AS table_name, | ||||||||||
| 64 | i.relname AS index_name, | ||||||||||
| 65 | am.amname AS index_type, | ||||||||||
| 66 | idx.indkey, | ||||||||||
| 67 | ARRAY( | ||||||||||
| 68 | SELECT | ||||||||||
| 69 | pg_get_indexdef(idx.indexrelid, k + 1, TRUE) | ||||||||||
| 70 | FROM | ||||||||||
| 71 | generate_subscripts(idx.indkey, 1) AS k | ||||||||||
| 72 | ORDER BY k | ||||||||||
| 73 | ) AS index_keys, | ||||||||||
| 74 | (idx.indexprs IS NOT NULL) OR (idx.indkey::int[] @> array[0]) AS is_functional, | ||||||||||
| 75 | idx.indpred IS NOT NULL AS is_partial | ||||||||||
| 76 | FROM | ||||||||||
| 77 | pg_index AS idx | ||||||||||
| 78 | JOIN pg_class AS i ON i.oid = idx.indexrelid | ||||||||||
| 79 | JOIN pg_am AS am ON i.relam = am.oid | ||||||||||
| 80 | JOIN pg_namespace AS NS ON i.relnamespace = NS.OID | ||||||||||
| 81 | JOIN pg_user AS U ON i.relowner = U.usesysid | ||||||||||
| 82 | WHERE | ||||||||||
| 83 | NOT nspname LIKE 'pg%' | ||||||||||
| 84 | AND NOT idx.indisprimary | ||||||||||
| 85 | AND NOT idx.indisunique~; | ||||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 1 | 1; # End of Geoffrey::Converter::Pg::Index | |||||||||
| 89 | |||||||||||
| 90 | __END__ | ||||||||||