| 1 | package Geoffrey::Converter::Pg; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | $Geoffrey::Converter::Pg::VERSION = '0.000201'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use parent 'Geoffrey::Role::Converter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | Readonly::Scalar my $I_CONST_LENGTH_VALUE => 2; | |||||||||||||||||||||||||||
| 14 | 4 | Readonly::Scalar my $I_CONST_NOT_NULL_VALUE => 3; | |||||||||||||||||||||||||||
| 15 | 4 | Readonly::Scalar my $I_CONST_PRIMARY_KEY_VALUE => 4; | |||||||||||||||||||||||||||
| 16 | 4 | Readonly::Scalar my $I_CONST_DEFAULT_VALUE => 5; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | package Geoffrey::Converter::Pg::Constraints; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | return bless $class->SUPER::new( | |||||||||||||||||||||||||||
| 27 | not_null => 'NOT NULL', | ||||||||||||||||||||||||||||
| 28 | unique => 'UNIQUE', | ||||||||||||||||||||||||||||
| 29 | primary_key => 'PRIMARY KEY', | ||||||||||||||||||||||||||||
| 30 | foreign_key => 'FOREIGN KEY', | ||||||||||||||||||||||||||||
| 31 | check => 'CHECK', | ||||||||||||||||||||||||||||
| 32 | default => 'DEFAULT', | ||||||||||||||||||||||||||||
| 33 | ), $class; | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | package Geoffrey::Converter::Pg::View; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub add { return 'CREATE VIEW {0} AS {1}'; } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub drop { return 'DROP VIEW {0}'; } | ||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub list { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my ($self, $schema) = @_; | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 0 | return q~SELECT * FROM pg_views WHERE schemaname NOT IN('information_schema', 'pg_catalog')~; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | package Geoffrey::Converter::Pg::ForeignKey; | |||||||||||||||||||||||||||
| 54 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub add { return 'FOREIGN KEY ({0}) REFERENCES {1}({2})' } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub list { | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return q~SELECT | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | source_table::regclass, | ||||||||||||||||||||||||||||
| 60 | source_attr.attname AS source_column, | ||||||||||||||||||||||||||||
| 61 | target_table::regclass, | ||||||||||||||||||||||||||||
| 62 | target_attr.attname AS target_column | ||||||||||||||||||||||||||||
| 63 | FROM | ||||||||||||||||||||||||||||
| 64 | pg_attribute target_attr, | ||||||||||||||||||||||||||||
| 65 | pg_attribute source_attr, | ||||||||||||||||||||||||||||
| 66 | ( | ||||||||||||||||||||||||||||
| 67 | SELECT | ||||||||||||||||||||||||||||
| 68 | source_table, | ||||||||||||||||||||||||||||
| 69 | target_table, | ||||||||||||||||||||||||||||
| 70 | source_constraints[i] AS source_constraints, | ||||||||||||||||||||||||||||
| 71 | target_constraints[i] AS target_constraints | ||||||||||||||||||||||||||||
| 72 | FROM ( | ||||||||||||||||||||||||||||
| 73 | SELECT | ||||||||||||||||||||||||||||
| 74 | conrelid as source_table, | ||||||||||||||||||||||||||||
| 75 | confrelid AS target_table, | ||||||||||||||||||||||||||||
| 76 | conkey AS source_constraints, | ||||||||||||||||||||||||||||
| 77 | confkey AS target_constraints, | ||||||||||||||||||||||||||||
| 78 | generate_series(1, array_upper(conkey, 1)) AS i | ||||||||||||||||||||||||||||
| 79 | FROM | ||||||||||||||||||||||||||||
| 80 | pg_constraint | ||||||||||||||||||||||||||||
| 81 | WHERE | ||||||||||||||||||||||||||||
| 82 | contype = 'f' | ||||||||||||||||||||||||||||
| 83 | ) query1 | ||||||||||||||||||||||||||||
| 84 | ) query2 | ||||||||||||||||||||||||||||
| 85 | WHERE | ||||||||||||||||||||||||||||
| 86 | target_attr.attnum = target_constraints | ||||||||||||||||||||||||||||
| 87 | AND target_attr.attrelid = target_table | ||||||||||||||||||||||||||||
| 88 | AND source_attr.attnum = source_constraints | ||||||||||||||||||||||||||||
| 89 | AND source_attr.attrelid = source_table~; | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 4 | package Geoffrey::Converter::Pg::Sequence; | |||||||||||||||||||||||||||
| 95 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub add { return 'CREATE SEQUENCE {0} INCREMENT {1} MINVALUE {2} MAXVALUE {3} START {4} CACHE {5}' } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub nextval { return q~DEFAULT nextval('{0}'::regclass~ } | ||||||||||||||||||||||||||
|
Subroutine
nextval: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | package Geoffrey::Converter::Pg::PrimaryKey; | |||||||||||||||||||||||||||
| 103 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub add { return 'CONSTRAINT {0} PRIMARY KEY ( {1} )'; } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | sub list { | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return q~SELECT | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | tc.table_schema, | ||||||||||||||||||||||||||||
| 109 | tc.table_name, | ||||||||||||||||||||||||||||
| 110 | kc.column_name, | ||||||||||||||||||||||||||||
| 111 | kc.constraint_name | ||||||||||||||||||||||||||||
| 112 | FROM | ||||||||||||||||||||||||||||
| 113 | information_schema.table_constraints tc, | ||||||||||||||||||||||||||||
| 114 | information_schema.key_column_usage kc | ||||||||||||||||||||||||||||
| 115 | WHERE | ||||||||||||||||||||||||||||
| 116 | tc.constraint_type = 'PRIMARY KEY' | ||||||||||||||||||||||||||||
| 117 | AND kc.table_name = tc.table_name | ||||||||||||||||||||||||||||
| 118 | AND kc.table_schema = tc.table_schema | ||||||||||||||||||||||||||||
| 119 | AND kc.constraint_name = tc.constraint_name~; | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 4 | package Geoffrey::Converter::Pg::UniqueIndex; | |||||||||||||||||||||||||||
| 125 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub append { return 'CREATE UNIQUE INDEX IF NOT EXISTS {0} ON {1} ( {2} )'; } | ||||||||||||||||||||||||||
|
Subroutine
append: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub add { return 'CONSTRAINT {0} UNIQUE ( {1} )'; } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub drop { return 'DROP INDEX IF EXISTS {1}'; } | ||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub list { | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | list => q~SELECT | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 132 | U.usename AS user_name, | ||||||||||||||||||||||||||||
| 133 | ns.nspname AS schema_name, | ||||||||||||||||||||||||||||
| 134 | idx.indrelid :: REGCLASS AS table_name, | ||||||||||||||||||||||||||||
| 135 | i.relname AS index_name, | ||||||||||||||||||||||||||||
| 136 | am.amname AS index_type, | ||||||||||||||||||||||||||||
| 137 | idx.indkey, | ||||||||||||||||||||||||||||
| 138 | ARRAY( | ||||||||||||||||||||||||||||
| 139 | SELECT | ||||||||||||||||||||||||||||
| 140 | pg_get_indexdef(idx.indexrelid, k + 1, TRUE) | ||||||||||||||||||||||||||||
| 141 | FROM | ||||||||||||||||||||||||||||
| 142 | generate_subscripts(idx.indkey, 1) AS k | ||||||||||||||||||||||||||||
| 143 | ORDER BY k | ||||||||||||||||||||||||||||
| 144 | ) AS index_keys, | ||||||||||||||||||||||||||||
| 145 | (idx.indexprs IS NOT NULL) OR (idx.indkey::int[] @> array[0]) AS is_functional, | ||||||||||||||||||||||||||||
| 146 | idx.indpred IS NOT NULL AS is_partial | ||||||||||||||||||||||||||||
| 147 | FROM | ||||||||||||||||||||||||||||
| 148 | pg_index AS idx | ||||||||||||||||||||||||||||
| 149 | JOIN pg_class AS i ON i.oid = idx.indexrelid | ||||||||||||||||||||||||||||
| 150 | JOIN pg_am AS am ON i.relam = am.oid | ||||||||||||||||||||||||||||
| 151 | JOIN pg_namespace AS NS ON i.relnamespace = NS.OID | ||||||||||||||||||||||||||||
| 152 | JOIN pg_user AS U ON i.relowner = U.usesysid | ||||||||||||||||||||||||||||
| 153 | WHERE | ||||||||||||||||||||||||||||
| 154 | NOT nspname LIKE 'pg%' | ||||||||||||||||||||||||||||
| 155 | AND NOT idx.indisprimary | ||||||||||||||||||||||||||||
| 156 | AND idx.indisunique;~; | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 4 | package Geoffrey::Converter::Pg::Function; | |||||||||||||||||||||||||||
| 162 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub add { return q~CREATE FUNCTION {0}({1}) RETURNS {2} AS ' {3} ' LANGUAGE {4} VOLATILE COST {5}~; } | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub drop { return 'DROP FUNCTION {0} ({1})'; } | ||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | sub list { | ||||||||||||||||||||||||||||
| 167 | 0 | ▶ | list => q~SELECT n.nspname as "Schema", | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 168 | p.proname as "Name", | ||||||||||||||||||||||||||||
| 169 | p.prosrc, | ||||||||||||||||||||||||||||
| 170 | p.procost, | ||||||||||||||||||||||||||||
| 171 | pg_catalog.pg_get_function_result(p.oid) as result_data_type, | ||||||||||||||||||||||||||||
| 172 | pg_catalog.pg_get_function_arguments(p.oid) as argument_data_types, | ||||||||||||||||||||||||||||
| 173 | CASE | ||||||||||||||||||||||||||||
| 174 | WHEN p.proisagg THEN 'agg' | ||||||||||||||||||||||||||||
| 175 | WHEN p.proiswindow THEN 'window' | ||||||||||||||||||||||||||||
| 176 | WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 'trigger' | ||||||||||||||||||||||||||||
| 177 | ELSE | ||||||||||||||||||||||||||||
| 178 | 'normal' | ||||||||||||||||||||||||||||
| 179 | END as | ||||||||||||||||||||||||||||
| 180 | function_type | ||||||||||||||||||||||||||||
| 181 | FROM | ||||||||||||||||||||||||||||
| 182 | pg_catalog.pg_proc p | ||||||||||||||||||||||||||||
| 183 | LEFT JOIN pg_catalog.pg_namespace n | ||||||||||||||||||||||||||||
| 184 | ON ( n.oid = p.pronamespace ) | ||||||||||||||||||||||||||||
| 185 | WHERE | ||||||||||||||||||||||||||||
| 186 | pg_catalog.pg_function_is_visible( p.oid ) | ||||||||||||||||||||||||||||
| 187 | AND n.nspname <> 'pg_catalog' | ||||||||||||||||||||||||||||
| 188 | AND n.nspname <> 'information_schema'~; | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 4 | package Geoffrey::Converter::Pg::Trigger; | |||||||||||||||||||||||||||
| 194 | 4 | ▶ | use parent 'Geoffrey::Role::ConverterType'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | sub add { | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my ($self, $options) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 198 | 0 | my $s_sql_standard = <<'EOF'; | |||||||||||||||||||||||||||
| 199 | CREATE TRIGGER {0} UPDATE OF {1} ON {2} | ||||||||||||||||||||||||||||
| 200 | BEGIN | ||||||||||||||||||||||||||||
| 201 | {4} | ||||||||||||||||||||||||||||
| 202 | END | ||||||||||||||||||||||||||||
| 203 | EOF | ||||||||||||||||||||||||||||
| 204 | 0 | my $s_sql_view = <<'EOF'; | |||||||||||||||||||||||||||
| 205 | CREATE TRIGGER {0} INSTEAD OF UPDATE OF {1} ON {2} | ||||||||||||||||||||||||||||
| 206 | BEGIN | ||||||||||||||||||||||||||||
| 207 | {4} | ||||||||||||||||||||||||||||
| 208 | END | ||||||||||||||||||||||||||||
| 209 | EOF | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return $options->{for_view} ? $s_sql_view : $s_sql_standard; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub drop { return 'DROP TRIGGER IF EXISTS {1}'; } | ||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 4 | sub new { | |||||||||||||||||||||||||||
| 217 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 218 | 2 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 219 | 2 | $self->{min_version} = '9.1'; | |||||||||||||||||||||||||||
| 220 | 2 | return bless $self, $class; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | sub defaults { | ||||||||||||||||||||||||||||
| 224 | 1 | ▶ | return {current_timestamp => 'CURRENT_TIMESTAMP', autoincrement => 'SERIAL',}; | ||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | sub type { | ||||||||||||||||||||||||||||
| 228 | 2 | ▶ | my ($self, $hr_column_params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=5 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 2 | ▶ | if ($hr_column_params->{default} && $hr_column_params->{default} eq 'autoincrement') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hr_column_params->{"default"} and $hr_column_params->{"default"} eq "autoincrement"
MC/DC0%0/2
$hr_column_params->{"default"} and $hr_column_params->{"default"} eq "autoincrement"
$hr_column_params->{"default"}
$hr_column_params->{"default"} eq "autoincrement"
Truth table33%1/3
A and B
A= $hr_column_params->{"default"}B= $hr_column_params->{"default"} eq "autoincrement"
| |||||||||||||||||||||||||||||
| 230 | $hr_column_params->{type} | ||||||||||||||||||||||||||||
| 231 | = lc $hr_column_params->{type} eq 'bigint' ? 'bigserial' | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | : lc $hr_column_params->{type} eq 'smallint' ? 'smallserial' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 233 | : 'serial'; | ||||||||||||||||||||||||||||
| 234 | 0 | delete $hr_column_params->{default}; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 2 | return $self->SUPER::type($hr_column_params); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | sub types { | ||||||||||||||||||||||||||||
| 240 | return { | ||||||||||||||||||||||||||||
| 241 | 2 | ▶ | abstime => 'abstime', | ||||||||||||||||||||||||||
|
Subroutine
types: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 242 | aclitem => 'aclitem', | ||||||||||||||||||||||||||||
| 243 | bigint => 'bigint', | ||||||||||||||||||||||||||||
| 244 | bigserial => 'bigserial', | ||||||||||||||||||||||||||||
| 245 | bit => 'bit', | ||||||||||||||||||||||||||||
| 246 | var_bit => 'bit varying', | ||||||||||||||||||||||||||||
| 247 | bool => 'boolean', | ||||||||||||||||||||||||||||
| 248 | box => 'box', | ||||||||||||||||||||||||||||
| 249 | bytea => 'bytea', | ||||||||||||||||||||||||||||
| 250 | char => '"char"', | ||||||||||||||||||||||||||||
| 251 | character => 'character', | ||||||||||||||||||||||||||||
| 252 | varchar => 'character varying', | ||||||||||||||||||||||||||||
| 253 | cid => 'cid', | ||||||||||||||||||||||||||||
| 254 | cidr => 'cidr', | ||||||||||||||||||||||||||||
| 255 | circle => 'circle', | ||||||||||||||||||||||||||||
| 256 | date => 'date', | ||||||||||||||||||||||||||||
| 257 | daterange => 'daterange', | ||||||||||||||||||||||||||||
| 258 | decimal => 'decimal', | ||||||||||||||||||||||||||||
| 259 | double_precision => 'double precision', | ||||||||||||||||||||||||||||
| 260 | gtsvector => 'gtsvector', | ||||||||||||||||||||||||||||
| 261 | inet => 'inet', | ||||||||||||||||||||||||||||
| 262 | int2vector => 'int2vector', | ||||||||||||||||||||||||||||
| 263 | int4range => 'int4range', | ||||||||||||||||||||||||||||
| 264 | int8range => 'int8range', | ||||||||||||||||||||||||||||
| 265 | integer => 'integer', | ||||||||||||||||||||||||||||
| 266 | interval => 'interval', | ||||||||||||||||||||||||||||
| 267 | json => 'json', | ||||||||||||||||||||||||||||
| 268 | line => 'line', | ||||||||||||||||||||||||||||
| 269 | lseg => 'lseg', | ||||||||||||||||||||||||||||
| 270 | macaddr => 'macaddr', | ||||||||||||||||||||||||||||
| 271 | money => 'money', | ||||||||||||||||||||||||||||
| 272 | name => 'name', | ||||||||||||||||||||||||||||
| 273 | numeric => 'numeric', | ||||||||||||||||||||||||||||
| 274 | numrange => 'numrange', | ||||||||||||||||||||||||||||
| 275 | oid => 'oid', | ||||||||||||||||||||||||||||
| 276 | oidvector => 'oidvector', | ||||||||||||||||||||||||||||
| 277 | path => 'path', | ||||||||||||||||||||||||||||
| 278 | pg_node_tree => 'pg_node_tree', | ||||||||||||||||||||||||||||
| 279 | point => 'point', | ||||||||||||||||||||||||||||
| 280 | polygon => 'polygon', | ||||||||||||||||||||||||||||
| 281 | real => 'real', | ||||||||||||||||||||||||||||
| 282 | refcursor => 'refcursor', | ||||||||||||||||||||||||||||
| 283 | regclass => 'regclass', | ||||||||||||||||||||||||||||
| 284 | regconfig => 'regconfig', | ||||||||||||||||||||||||||||
| 285 | regdictionary => 'regdictionary', | ||||||||||||||||||||||||||||
| 286 | regoper => 'regoper', | ||||||||||||||||||||||||||||
| 287 | regoperator => 'regoperator', | ||||||||||||||||||||||||||||
| 288 | regproc => 'regproc', | ||||||||||||||||||||||||||||
| 289 | regprocedure => 'regprocedure', | ||||||||||||||||||||||||||||
| 290 | regtype => 'regtype', | ||||||||||||||||||||||||||||
| 291 | reltime => 'reltime', | ||||||||||||||||||||||||||||
| 292 | serial => 'serial', | ||||||||||||||||||||||||||||
| 293 | smallint => 'smallint', | ||||||||||||||||||||||||||||
| 294 | smallserial => 'smallserial', | ||||||||||||||||||||||||||||
| 295 | smgr => 'smgr', | ||||||||||||||||||||||||||||
| 296 | text => 'text', | ||||||||||||||||||||||||||||
| 297 | tid => 'tid', | ||||||||||||||||||||||||||||
| 298 | timestamp => 'timestamp without time zone', | ||||||||||||||||||||||||||||
| 299 | timestamp_tz => 'timestamp with time zone', | ||||||||||||||||||||||||||||
| 300 | time => 'time without time zone', | ||||||||||||||||||||||||||||
| 301 | time_tz => 'time with time zone', | ||||||||||||||||||||||||||||
| 302 | tinterval => 'tinterval', | ||||||||||||||||||||||||||||
| 303 | tsquery => 'tsquery', | ||||||||||||||||||||||||||||
| 304 | tsrange => 'tsrange', | ||||||||||||||||||||||||||||
| 305 | tstzrange => 'tstzrange', | ||||||||||||||||||||||||||||
| 306 | tsvector => 'tsvector', | ||||||||||||||||||||||||||||
| 307 | txid_snapshot => 'txid_snapshot', | ||||||||||||||||||||||||||||
| 308 | uuid => 'uuid', | ||||||||||||||||||||||||||||
| 309 | xid => 'xid', | ||||||||||||||||||||||||||||
| 310 | xml => 'xml', | ||||||||||||||||||||||||||||
| 311 | }; | ||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | sub select_get_table { | ||||||||||||||||||||||||||||
| 315 | return | ||||||||||||||||||||||||||||
| 316 | 1 | ▶ | q~SELECT t.table_name AS table_name FROM information_schema.tables t WHERE t.table_type = 'BASE TABLE' AND t.table_schema = ? AND t.table_name = ?~; | ||||||||||||||||||||||||||
|
Subroutine
select_get_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | sub convert_defaults { | ||||||||||||||||||||||||||||
| 320 | 2 | ▶ | my ($self, $params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
convert_defaults: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 321 | 2 | ▶ | $params->{default} ? $params->{default} =~ s/^'(.*)'$/$1/ : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 2 | ▶ | if ($params->{default} && $params->{type} eq 'bit') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params->{"default"} and $params->{"type"} eq "bit"
MC/DC50%1/2
$params->{"default"} and $params->{"type"} eq "bit"
$params->{"default"}
$params->{"type"} eq "bit"
Truth table66%2/3
A and B
A= $params->{"default"}B= $params->{"type"} eq "bit"
| |||||||||||||||||||||||||||||
| 323 | 1 | return qq~$params->{default}::bit~; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | 1 | return $params->{default}; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | sub parse_default { | ||||||||||||||||||||||||||||
| 329 | 1 | ▶ | my ($self, $default_value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_default: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 330 | 1 | ▶ | return $1 * 1 if ($default_value =~ m/\w+\s*(?:\((\d+)\))::(.*)(?:\;|\s)/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 1 | return $default_value; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 1 | ▶ | sub can_create_empty_table { return 1 } | ||||||||||||||||||||||||||
|
Subroutine
can_create_empty_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | sub colums_information { | ||||||||||||||||||||||||||||
| 337 | 1 | ▶ | my ($self, $ar_raw_data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
colums_information: called CC=9 SCAR=28.1
Pod
documented
| |||||||||||||||||||||||||||||
| 338 | 1 | ▶ | return [] if scalar @{$ar_raw_data} == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 1 | my $table_row = shift @{$ar_raw_data}; | |||||||||||||||||||||||||||
| 340 | 1 | $table_row->{sql} =~ s/^.*(CREATE|create) .*\(//g; | |||||||||||||||||||||||||||
| 341 | 1 | my $columns = []; | |||||||||||||||||||||||||||
| 342 | 1 | for (split m/,/, $table_row->{sql}) { | |||||||||||||||||||||||||||
| 343 | 7 | s/^\s*(.*)\s*$/$1/g; | |||||||||||||||||||||||||||
| 344 | 7 | my $rx_not_null = 'NOT NULL'; | |||||||||||||||||||||||||||
| 345 | 7 | my $rx_primary_key = 'PRIMARY KEY'; | |||||||||||||||||||||||||||
| 346 | 7 | my $rx_default = 'SERIAL|DEFAULT'; | |||||||||||||||||||||||||||
| 347 | 7 | my $rx_column_values = qr/($rx_not_null)*\s($rx_primary_key)*.*($rx_default \w{1,})*/; | |||||||||||||||||||||||||||
| 348 | 7 | my @column = m/^(\w+)\s([[:upper:]]+)(\(\d*\))*\s$rx_column_values$/; | |||||||||||||||||||||||||||
| 349 | 7 | ▶ | next if scalar @column == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $column[$I_CONST_LENGTH_VALUE] =~ s/([\(\)])//g if $column[$I_CONST_LENGTH_VALUE]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | push @{$columns}, | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||
| 353 | name => $column[0], | ||||||||||||||||||||||||||||
| 354 | type => $column[1], | ||||||||||||||||||||||||||||
| 355 | ($column[$I_CONST_LENGTH_VALUE] ? (length => $column[$I_CONST_LENGTH_VALUE]) : ()), | ||||||||||||||||||||||||||||
| 356 | ($column[$I_CONST_NOT_NULL_VALUE] ? (not_null => $column[$I_CONST_NOT_NULL_VALUE]) : ()), | ||||||||||||||||||||||||||||
| 357 | ($column[$I_CONST_PRIMARY_KEY_VALUE] ? (primary_key => $column[$I_CONST_PRIMARY_KEY_VALUE]) : ()), | ||||||||||||||||||||||||||||
| 358 | ($column[$I_CONST_DEFAULT_VALUE] ? (default => $column[$I_CONST_DEFAULT_VALUE]) : ()), | ||||||||||||||||||||||||||||
| 359 | }; | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 1 | return $columns; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | sub index_information { | ||||||||||||||||||||||||||||
| 365 | 1 | ▶ | my ($self, $ar_raw_data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
index_information: called CC=4 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||
| 366 | 1 | my @mapped = (); | |||||||||||||||||||||||||||
| 367 | 1 | for (@{$ar_raw_data}) { | |||||||||||||||||||||||||||
| 368 | 0 | ▶ | next if !$_->{sql}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | my ($s_columns) = $_->{sql} =~ m/\((.*)\)$/; | |||||||||||||||||||||||||||
| 370 | 0 | my @columns = split m/,/, $s_columns; | |||||||||||||||||||||||||||
| 371 | 0 | s/^\s+|\s+$//g for @columns; | |||||||||||||||||||||||||||
| 372 | 0 | push @mapped, {name => $_->{name}, table => $_->{tbl_name}, columns => \@columns}; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | 1 | return \@mapped; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | sub view_information { | ||||||||||||||||||||||||||||
| 378 | 1 | ▶ | my ($self, $ar_raw_data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
view_information: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 379 | 1 | ▶ | return [] unless $ar_raw_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 1 | return [map { {name => $_->{name}, sql => $_->{sql}} } @{$ar_raw_data}]; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | sub constraints { | ||||||||||||||||||||||||||||
| 384 | 1 | ▶ | return shift->_get_value('constraints', 'Geoffrey::Converter::Pg::Constraints', 1); | ||||||||||||||||||||||||||
|
Subroutine
constraints: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | sub index { | ||||||||||||||||||||||||||||
| 388 | 1 | ▶ | my ($self, $new_value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
index: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 389 | 1 | ▶ | $self->{index} = $new_value if defined $new_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 1 | return $self->_get_value('index', 'Geoffrey::Converter::Pg::Index'); | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | sub table { | ||||||||||||||||||||||||||||
| 394 | 1 | ▶ | return shift->_get_value('table', 'Geoffrey::Converter::Pg::Tables'); | ||||||||||||||||||||||||||
|
Subroutine
table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | sub view { | ||||||||||||||||||||||||||||
| 398 | 1 | ▶ | return shift->_get_value('view', 'Geoffrey::Converter::Pg::View', 1); | ||||||||||||||||||||||||||
|
Subroutine
view: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | sub foreign_key { | ||||||||||||||||||||||||||||
| 402 | 1 | ▶ | my ($self, $new_value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
foreign_key: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | 1 | ▶ | $self->{foreign_key} = $new_value if defined $new_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 1 | return $self->_get_value('foreign_key', 'Geoffrey::Converter::Pg::ForeignKey', 1); | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | sub trigger { | ||||||||||||||||||||||||||||
| 408 | 1 | ▶ | return shift->_get_value('trigger', 'Geoffrey::Converter::Pg::Trigger', 1); | ||||||||||||||||||||||||||
|
Subroutine
trigger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | sub primary_key { | ||||||||||||||||||||||||||||
| 412 | 1 | ▶ | return shift->_get_value('primary_key', 'Geoffrey::Converter::Pg::PrimaryKey', 1); | ||||||||||||||||||||||||||
|
Subroutine
primary_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | sub unique { | ||||||||||||||||||||||||||||
| 416 | 1 | ▶ | return shift->_get_value('unique', 'Geoffrey::Converter::Pg::UniqueIndex', 1); | ||||||||||||||||||||||||||
|
Subroutine
unique: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | sub sequence { | ||||||||||||||||||||||||||||
| 420 | 1 | ▶ | return shift->_get_value('sequence', 'Geoffrey::Converter::Pg::Sequence', 1); | ||||||||||||||||||||||||||
|
Subroutine
sequence: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | sub _get_value { | ||||||||||||||||||||||||||||
| 424 | 9 | ▶ | my ($self, $key, $s_package_name, $b_ignore_require) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_value: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 425 | 9 | ▶ | $self->{$key} //= $self->_set_value($key, $s_package_name, $b_ignore_require); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{$key} //= $self->_set_value($key, $s_package_name, $b_ignore_require)
MC/DC0%0/2
$self->{$key} //= $self->_set_value($key, $s_package_name, $b_ignore_require)
$self->{$key}
$self->_set_value($key, $s_package_name, $b_ignore_require)
Truth table33%1/3
A //= B
A= $self->{$key}B= $self->_set_value($key, $s_package_name, $b_ignore_require)
| |||||||||||||||||||||||||||||
| 426 | 9 | return $self->{$key}; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | sub _set_value { | ||||||||||||||||||||||||||||
| 430 | 9 | ▶ | my ($self, $key, $s_package_name, $b_ignore_require) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 431 | 9 | require Geoffrey::Utils; | |||||||||||||||||||||||||||
| 432 | 9 | ▶ | $self->{$key} = $b_ignore_require ? $s_package_name->new(@_) : Geoffrey::Utils::obj_from_name($s_package_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 9 | return $self->{$key}; | |||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 4 | 1; # End of Geoffrey::Converter::Pg | |||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | __END__ | ||||||||||||||||||||||||||||