]> git.donarmstrong.com Git - cran2deb.git/commitdiff
support postgresql in addition to sqlite
authorDon Armstrong <don@donarmstrong.com>
Fri, 19 Jun 2015 19:46:09 +0000 (12:46 -0700)
committerDon Armstrong <don@donarmstrong.com>
Fri, 19 Jun 2015 19:46:09 +0000 (12:46 -0700)
trunk/R/db.R

index 2dc68926ddd90a33ee3e4e436c29da03289eea83..d604e7f2966b958bc8817dd2ddc590edac80c72b 100644 (file)
@@ -1,9 +1,22 @@
 
 db_start <- function() {
-    drv <- dbDriver('SQLite')
-    if (is.null(drv)) stop("db_start: Could not access driver for SQLite.\n")
-    con <- dbConnect(drv, dbname=file.path(cache_root,'cran2deb.db'))
-    if (is.null(con)) stop("db_start: Could open connection to file 'cran2deb.db' in directory",cache_root,".\n")
+    pg.service <- Sys.getenv('CRAN2DEB_PG')
+    if (!is.null(pg.service) &&
+        any(grepl(".",pg.service))) {
+        drv <- dbDriver("PostgreSQL")
+        if (is.null(drv)) {
+            stop("db_start: Could not access driver for postgresql.")
+        }
+        con <- dbConnect(drv,service=pg.service)
+        if (is.null(con)) {
+            stop("db_start: Could open connection to service ",pg.service)
+        }
+    } else {
+        drv <- dbDriver('SQLite')
+        if (is.null(drv)) stop("db_start: Could not access driver for SQLite.\n")
+        con <- dbConnect(drv, dbname=file.path(cache_root,'cran2deb.db'))
+        if (is.null(con)) stop("db_start: Could open connection to file 'cran2deb.db' in directory",cache_root,".\n")
+    }
     if (!dbExistsTable(con,'sysreq_override')) {
         dbGetQuery(con,paste('CREATE TABLE sysreq_override ('
                   ,' depend_alias TEXT NOT NULL'