]> ruin.nu Git - ND.git/commitdiff
Finally add DB.pm
authorMichael Andreen <harv@ruin.nu>
Tue, 17 Jun 2008 21:31:09 +0000 (23:31 +0200)
committerMichael Andreen <harv@ruin.nu>
Tue, 17 Jun 2008 21:31:09 +0000 (23:31 +0200)
.gitignore
DB.pm [new file with mode: 0644]

index 808a82db0a9414abf0aad0d4a563183fcc3ceeed..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-DB.pm
diff --git a/DB.pm b/DB.pm
new file mode 100644 (file)
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;
+