| 1 | package DBIO::PostgreSQL::Introspect::Sequences; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Introspect PostgreSQL sequences | ||||||||||||||||||||||||||||
| 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=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 0 | my ($class, $dbh, $filter) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | my $sql = q{ | |||||||||||||||||||||||||||
| 15 | SELECT | ||||||||||||||||||||||||||||
| 16 | sn.nspname AS schema_name, | ||||||||||||||||||||||||||||
| 17 | s.relname AS sequence_name, | ||||||||||||||||||||||||||||
| 18 | d.refobjid::regclass::text AS owned_by_table, | ||||||||||||||||||||||||||||
| 19 | a.attname AS owned_by_column, | ||||||||||||||||||||||||||||
| 20 | seq.seqstart AS start_value, | ||||||||||||||||||||||||||||
| 21 | seq.seqincrement AS increment, | ||||||||||||||||||||||||||||
| 22 | seq.seqmin AS min_value, | ||||||||||||||||||||||||||||
| 23 | seq.seqmax AS max_value, | ||||||||||||||||||||||||||||
| 24 | seq.seqcache AS cache_size, | ||||||||||||||||||||||||||||
| 25 | seq.seqcycle AS is_cycle, | ||||||||||||||||||||||||||||
| 26 | pg_catalog.format_type(seq.seqtypid, NULL) AS data_type | ||||||||||||||||||||||||||||
| 27 | FROM pg_catalog.pg_class s | ||||||||||||||||||||||||||||
| 28 | JOIN pg_catalog.pg_namespace sn ON sn.oid = s.relnamespace | ||||||||||||||||||||||||||||
| 29 | JOIN pg_catalog.pg_sequence seq ON seq.seqrelid = s.oid | ||||||||||||||||||||||||||||
| 30 | LEFT JOIN pg_catalog.pg_depend d | ||||||||||||||||||||||||||||
| 31 | ON d.objid = s.oid AND d.deptype = 'a' | ||||||||||||||||||||||||||||
| 32 | LEFT JOIN pg_catalog.pg_attribute a | ||||||||||||||||||||||||||||
| 33 | ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid | ||||||||||||||||||||||||||||
| 34 | WHERE s.relkind = 'S' | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | 0 | $sql .= DBIO::PostgreSQL::Introspect->system_schema_filter('sn'); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my @bind; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($filter && @$filter) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$filter and @$filter
MC/DC0%0/2
$filter and @$filter
$filter
@$filter
Truth table0%0/3
A and B
A= $filterB= @$filter
| |||||||||||||||||||||||||||||
| 40 | 0 | $sql .= ' AND sn.nspname = ANY($1)'; | |||||||||||||||||||||||||||
| 41 | 0 | push @bind, $filter; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | $sql .= ' ORDER BY sn.nspname, s.relname'; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||||||||||
| 47 | 0 | $sth->execute(@bind); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | my %sequences; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my $key = DBIO::PostgreSQL::Introspect->qualified_key($row); | |||||||||||||||||||||||||||
| 52 | $sequences{$key} = { | ||||||||||||||||||||||||||||
| 53 | schema_name => $row->{schema_name}, | ||||||||||||||||||||||||||||
| 54 | sequence_name => $row->{sequence_name}, | ||||||||||||||||||||||||||||
| 55 | owned_by_table => $row->{owned_by_table}, | ||||||||||||||||||||||||||||
| 56 | owned_by_column => $row->{owned_by_column}, | ||||||||||||||||||||||||||||
| 57 | start_value => $row->{start_value}, | ||||||||||||||||||||||||||||
| 58 | increment => $row->{increment}, | ||||||||||||||||||||||||||||
| 59 | min_value => $row->{min_value}, | ||||||||||||||||||||||||||||
| 60 | max_value => $row->{max_value}, | ||||||||||||||||||||||||||||
| 61 | cache_size => $row->{cache_size}, | ||||||||||||||||||||||||||||
| 62 | is_cycle => $row->{is_cycle} ? 1 : 0, | ||||||||||||||||||||||||||||
| 63 | data_type => $row->{data_type}, | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | return \%sequences; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 15 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =pod | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | DBIO::PostgreSQL::Introspect::Sequences - Introspect PostgreSQL sequences | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 VERSION | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | version 0.900001 | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Fetches sequence metadata from C<pg_catalog.pg_sequence>, including ownership | ||||||||||||||||||||||||||||
| 89 | information (the table and column the sequence is attached to via C<pg_depend>), | ||||||||||||||||||||||||||||
| 90 | start value, increment, min/max bounds, cache size, cycle flag, and data type. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 METHODS | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 fetch | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | my $sequences = DBIO::PostgreSQL::Introspect::Sequences->fetch($dbh, $filter); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Returns a hashref keyed by C<schema.sequence_name>. Each entry has: | ||||||||||||||||||||||||||||
| 99 | C<schema_name>, C<sequence_name>, C<owned_by_table>, C<owned_by_column>, | ||||||||||||||||||||||||||||
| 100 | C<start_value>, C<increment>, C<min_value>, C<max_value>, C<cache_size>, | ||||||||||||||||||||||||||||
| 101 | C<is_cycle>, C<data_type>. | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||