]> ruin.nu Git - ND.git/blob - DB.pm
Don't print warnings and clean up better
[ND.git] / DB.pm
1 package ND::DB;
2 use strict;
3 use DBI;
4 use DBD::Pg qw(:pg_types);
5 require Exporter;
6
7 our @ISA = qw/Exporter/;
8
9 our @EXPORT = qw/DB/;
10
11
12 sub DB {
13         #Use domain sockets by default
14         my $dbh = DBI->connect_cached("dbi:Pg:dbname=ndawn", "ndawn", "", {AutoCommit => 1, RaiseError => 1});
15         #Easy to also use /etc/postgresql/pg_services.conf
16         #my $dbh =  DBI->connect_cached("dbi:Pg:service=ndawn","", "", {AutoCommit => 1});
17         {
18                 no warnings;
19                 local $dbh->{Warn} = 0;
20                 $dbh->do('ABORT; RESET ALL; SET SESSION AUTHORIZATION DEFAULT; DEALLOCATE ALL');
21         }
22         return $dbh;
23 };
24 1;
25