File: stag-connect-parameters.pl

package info (click to toggle)
libdbix-dbstag-perl 0.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,420 kB
  • sloc: perl: 6,152; sql: 588; xml: 221; lisp: 59; makefile: 20
file content (73 lines) | stat: -rwxr-xr-x 1,190 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/local/bin/perl

# cjm@fruitfly.org

# currently assumes Pg

use strict;
use Carp;
use DBIx::DBStag;
use Data::Stag qw(:all);
use Data::Dumper;
use Getopt::Long;

my $h = {};

my $dbname = '';
my $term;
my @hist = ();

GetOptions(
           "dbname|d=s"=>\$dbname,
          );

my $db = shift || $dbname;
# parent dbh
my $sdbh = 
  DBIx::DBStag->new;

my $resource = $sdbh->resources_hash->{$db};
my $pstr = '';
if ($resource) {
    my $loc = $resource->{loc};
    if ($loc =~ /(\w+):(\S+)\@(\S+)/) {
        $pstr = "-h $3 $2";
    }
    if (!$pstr) {
        print STDERR "Could not resolve: $db [from $loc]\n";
        exit 1;
    }
}
else {
    print STDERR "No such resource: $db\n";
    exit 1;
}

print $pstr;
exit 0;

__END__

=head1 NAME 

stag-connect-parameters.pl

=head1 SYNOPSIS

  alias db='stag-connect-parameters.pl -d'
  psql `db mydb`

=head1 DESCRIPTION

Looks up the connection parameters for a logical dbname in the metadata file pointed at by DBSTAG_DBIMAP_FILE

See L<selectall_xml.pl> for more on this mapping

=head2 ARGUMENTS

=head3 -d B<DBNAME>

This is either a DBI locator or the logical name of a database in the
DBSTAG_DBIMAP_FILE config file

=cut