PostgreSQL/Introspect/Tables.pm

filter: Statementstmt 40.0% 10 / 25 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 32.5% 14 / 43 CC 6 SCAR 33.4
CC
6
Cov
28%
fetch
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« PostgreSQL/Introspect/Functions.pm ↑ Summary PostgreSQL/Introspect.pm »
1 package DBIO::PostgreSQL::Introspect::Tables;
2 # ABSTRACT: Introspect PostgreSQL tables
3  
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use DBIO::PostgreSQL::Introspect ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10  
11 0 ▶sub fetch {
Subroutine fetch: not called CC=6 SCAR=37.4
Pod documented
12 0 my ($class, $dbh, $filter) = @_;
13  
14 0 my $sql = q{
15 SELECT
16 n.nspname AS schema_name,
17 c.relname AS table_name,
18 c.oid AS table_oid,
19 c.relkind AS kind,
20 c.relpersistence AS persistence,
21 CASE c.relkind
22 WHEN 'r' THEN 'table'
23 WHEN 'v' THEN 'view'
24 WHEN 'm' THEN 'materialized_view'
25 WHEN 'f' THEN 'foreign_table'
26 WHEN 'p' THEN 'partitioned_table'
27 END AS kind_label,
28 pg_catalog.obj_description(c.oid, 'pg_class') AS comment,
29 c.relrowsecurity AS rls_enabled,
30 c.relforcerowsecurity AS rls_forced,
31 CASE
32 WHEN c.relkind IN ('v', 'm') THEN pg_catalog.pg_get_viewdef(c.oid)
33 END AS view_definition
34 FROM pg_catalog.pg_class c
35 JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
36 WHERE c.relkind IN ('r', 'v', 'm', 'f', 'p')
37 };
38 0 $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('n');
39  
40 0 my @bind;
41 0 ▶ if ($filter && @$filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter and @$filter) 0 0 0
Condition0%0/3
$filter and @$filter
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and @$filter
$filter @$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
ABresult
0X0
100
111
42 0 $sql .= ' AND n.nspname = ANY($1)';
43 0 push @bind, $filter;
44 }
45  
46 0 $sql .= ' ORDER BY n.nspname, c.relname';
47  
48 0 my $sth = $dbh->prepare($sql);
49 0 $sth->execute(@bind);
50  
51 0 my %tables;
52 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
53 0 my $key = DBIO::PostgreSQL::Introspect->qualified_key($row);
54 $tables{$key} = {
55 schema_name => $row->{schema_name},
56 table_name => $row->{table_name},
57 oid => $row->{table_oid},
58 kind => $row->{kind},
59 kind_label => $row->{kind_label},
60 persistence => $row->{persistence},
61 comment => $row->{comment},
62 rls_enabled => $row->{rls_enabled} ? 1 : 0,
63 rls_forced => $row->{rls_forced} ? 1 : 0,
64 view_definition => $row->{view_definition},
65 0 ▶ };
Branch: 2 branches
BranchTrueFalseTotal
$row->{'rls_enabled'} ? : 0 0 0
$row->{'rls_forced'} ? : 0 0 0
66 }
67  
68 0 return \%tables;
69 }
70  
71 15 1;
72  
73 __END__
74  
75 =pod
76  
77 =encoding UTF-8
78  
79 =head1 NAME
80  
81 DBIO::PostgreSQL::Introspect::Tables - Introspect PostgreSQL tables
82  
83 =head1 VERSION
84  
85 version 0.900001
86  
87 =head1 DESCRIPTION
88  
89 Fetches PostgreSQL table (and view, materialized view, foreign table, and
90 partitioned table) metadata from C<pg_catalog.pg_class>.
91  
92 =head1 METHODS
93  
94 =head2 fetch
95  
96 my $tables = DBIO::PostgreSQL::Introspect::Tables->fetch($dbh, $filter);
97  
98 Returns a hashref keyed by C<schema.table>. Each value is a hashref with
99 keys: C<schema_name>, C<table_name>, C<oid>, C<kind> (pg relkind char),
100 C<kind_label> (human-readable), C<persistence>, C<comment>, C<rls_enabled>,
101 C<rls_forced>, C<view_definition>.
102  
103 =head1 AUTHOR
104  
105 DBIO & DBIx::Class Authors
106  
107 =head1 COPYRIGHT AND LICENSE
108  
109 Copyright (C) 2026 DBIO Authors
110 Portions Copyright (C) 2005-2025 DBIx::Class Authors
111 Based on DBIx::Class, heavily modified.
112  
113 This is free software; you can redistribute it and/or modify it under
114 the same terms as the Perl 5 programming language system itself.
115  
116 =cut
« PostgreSQL/Introspect/Functions.pm ↑ Summary PostgreSQL/Introspect.pm »