From: Michael Andreen Date: Tue, 17 Jun 2008 21:31:09 +0000 (+0200) Subject: Finally add DB.pm X-Git-Url: https://ruin.nu/git/?p=ND.git;a=commitdiff_plain;h=8fe7db805251b8b4bc2f1558e8a7216c63892a33 Finally add DB.pm --- diff --git a/.gitignore b/.gitignore index 808a82d..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +0,0 @@ -DB.pm diff --git a/DB.pm b/DB.pm new file mode 100644 index 0000000..76cb9dd --- /dev/null +++ b/DB.pm @@ -0,0 +1,21 @@ +package ND::DB; +use strict; +use DBI; +use DBD::Pg qw(:pg_types); +require Exporter; + +our @ISA = qw/Exporter/; + +our @EXPORT = qw/DB/; + + +sub DB { + #Use domain sockets by default + my $dbh = DBI->connect_cached("dbi:Pg:dbname=ndawn", "ndawn", "", {AutoCommit => 1}); + #Easy to also use /etc/postgresql/pg_services.conf + #my $dbh = DBI->connect_cached("dbi:Pg:service=ndawn","", "", {AutoCommit => 1}); + $dbh->rollback if $dbh->{Executed} || !$dbh->{AutoCommit}; + return $dbh; +}; +1; +