-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect_result.R
59 lines (56 loc) · 1.35 KB
/
connect_result.R
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
#' Opens an ODBC connection to the 'results' database
#' @export
#' @importFrom dplyr src_postgres
#' @param username the username to connect to the database.
#' @param password the password for the username.
#' @param develop Logical value. Indicates the location of the results database
#' @importFrom assertthat assert_that is.flag noNA is.string
connect_result <- function(username, password, develop = TRUE){
assert_that(is.flag(develop))
assert_that(noNA(develop))
assert_that(is.string(username))
assert_that(is.string(password))
dbname <- "n2kresult"
if (develop) {
# nocov start
host <- "localhost"
# nocov end
} else {
stop("Production database not yet defined")
}
# nocov start
src_postgres(
host = host,
dbname = dbname,
user = username,
password = password
)
# nocov end
}
#' Open a trusted connection to the NBN database
#' @export
connect_nbn <- function(){
odbcDriverConnect(connection = nbn.dsn)
}
#' connect to the unit test database
#' @inheritParams dplyr::src_postgres
#' @export
#' @importFrom dplyr src_postgres
connect_ut_db <- function(
host = "localhost",
dbname = "n2kunittest",
user = "unittest_analysis",
password = "unittest",
port = 5432,
...
){
# nocov start
src_postgres(
host = host,
dbname = dbname,
user = user,
password = password,
...
)
# nocov end
}