#521 Add back specific RPoostgreSQL methods and tests

Merged Jonathan Keane jonkeane
Showing 2 of 5 files from the diff.

@@ -0,0 +1,51 @@
Loading
1 +
#' @include backend-postgres.R
2 +
NULL
3 +
4 +
# Use dbplyr edition 1 for custom method dispatch on RPostgreSQL connections
5 +
#' @export
6 +
dbplyr_edition.PostgreSQLConnection <- function(con) {
7 +
  1L
8 +
}
9 +
10 +
#' @export
11 +
db_write_table.PostgreSQLConnection <- function(con, table, types, values,
12 +
                                                temporary = TRUE, overwrite = FALSE, ....) {
13 +
14 +
  dbWriteTable(
15 +
    con,
16 +
    name = table,
17 +
    value = values,
18 +
    field.types = types,
19 +
    temporary = temporary,
20 +
    overwrite = overwrite,
21 +
    row.names = FALSE
22 +
  )
23 +
24 +
  table
25 +
}
26 +
27 +
#' @export
28 +
db_query_fields.PostgreSQLConnection <- function(con, sql, ...) {
29 +
  fields <- build_sql(
30 +
    "SELECT * FROM ", sql_subquery(con, sql), " WHERE 0=1",
31 +
    con = con
32 +
  )
33 +
34 +
  qry <- dbSendQuery(con, fields)
35 +
  on.exit(dbClearResult(qry))
36 +
37 +
  dbGetInfo(qry)$fieldDescription[[1]]$name
38 +
}
39 +
40 +
41 +
#' @export
42 +
db_connection_describe.PostgreSQLConnection <- db_connection_describe.PqConnection
43 +
44 +
#' @export
45 +
sql_translation.PostgreSQLConnection <- sql_translation.PqConnection
46 +
47 +
#' @export
48 +
sql_expr_matches.PostgreSQLConnection <- sql_expr_matches.PqConnection
49 +
50 +
#' @export
51 +
sql_query_explain.PostgreSQLConnection <- sql_query_explain.PqConnection

@@ -24,29 +24,25 @@
Loading
24 24
25 25
#' @export
26 26
#' @rdname backend-postgres
27 -
simulate_postgres <- function() simulate_dbi("PostgreSQLConnection")
27 +
simulate_postgres <- function() simulate_dbi("PqConnection")
28 28
29 29
#' @export
30 -
dbplyr_edition.PostgreSQLConnection <- function(con) {
30 +
dbplyr_edition.PostgreSQL <- function(con) {
31 31
  2L
32 32
}
33 33
#' @export
34 -
dbplyr_edition.PostgreSQL <- dbplyr_edition.PostgreSQLConnection
35 -
#' @export
36 -
dbplyr_edition.PqConnection <- dbplyr_edition.PostgreSQLConnection
34 +
dbplyr_edition.PqConnection <- dbplyr_edition.PostgreSQL
37 35
38 36
#' @export
39 -
db_connection_describe.PostgreSQLConnection <- function(con) {
37 +
db_connection_describe.PqConnection <- function(con) {
40 38
  info <- dbGetInfo(con)
41 39
  host <- if (info$host == "") "localhost" else info$host
42 40
43 41
  paste0("postgres ", info$serverVersion, " [", info$user, "@",
44 42
    host, ":", info$port, "/", info$dbname, "]")
45 43
}
46 44
#' @export
47 -
db_connection_describe.PostgreSQL <- db_connection_describe.PostgreSQLConnection
48 -
#' @export
49 -
db_connection_describe.PqConnection <- db_connection_describe.PostgreSQLConnection
45 +
db_connection_describe.PostgreSQL <- db_connection_describe.PqConnection
50 46
51 47
postgres_grepl <- function(pattern, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) {
52 48
  # https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-TABLE
@@ -66,7 +62,7 @@
Loading
66 62
}
67 63
68 64
#' @export
69 -
sql_translation.PostgreSQLConnection <- function(con) {
65 +
sql_translation.PqConnection <- function(con) {
70 66
  sql_variant(
71 67
    sql_translator(.parent = base_scalar,
72 68
      bitwXor = sql_infix("#"),
@@ -213,25 +209,19 @@
Loading
213 209
  )
214 210
}
215 211
#' @export
216 -
sql_translation.PostgreSQL <- sql_translation.PostgreSQLConnection
217 -
#' @export
218 -
sql_translation.PqConnection <- sql_translation.PostgreSQLConnection
212 +
sql_translation.PostgreSQL <- sql_translation.PqConnection
219 213
220 214
#' @export
221 -
sql_expr_matches.PostgreSQLConnection <- function(con, x, y) {
215 +
sql_expr_matches.PqConnection <- function(con, x, y) {
222 216
  # https://www.postgresql.org/docs/current/functions-comparison.html
223 217
  build_sql(x, " IS NOT DISTINCT FROM ", y, con = con)
224 218
}
225 219
#' @export
226 -
sql_expr_matches.PostgreSQL <- sql_expr_matches.PostgreSQLConnection
227 -
#' @export
228 -
sql_expr_matches.PqConnection <- sql_expr_matches.PostgreSQLConnection
229 -
230 -
# DBI methods ------------------------------------------------------------------
220 +
sql_expr_matches.PostgreSQL <- sql_expr_matches.PqConnection
231 221
232 222
# http://www.postgresql.org/docs/9.3/static/sql-explain.html
233 223
#' @export
234 -
sql_query_explain.PostgreSQLConnection <- function(con, sql, format = "text", ...) {
224 +
sql_query_explain.PqConnection <- function(con, sql, format = "text", ...) {
235 225
  format <- match.arg(format, c("text", "json", "yaml", "xml"))
236 226
237 227
  build_sql(
@@ -242,8 +232,6 @@
Loading
242 232
  )
243 233
}
244 234
#' @export
245 -
sql_query_explain.PostgreSQL <- sql_query_explain.PostgreSQLConnection
246 -
#' @export
247 -
sql_query_explain.PqConnection <- sql_query_explain.PostgreSQLConnection
235 +
sql_query_explain.PostgreSQL <- sql_query_explain.PqConnection
248 236
249 237
globalVariables(c("strpos", "%::%", "%FROM%", "DATE", "EXTRACT", "TO_CHAR", "string_agg", "%~*%", "%~%", "MONTH", "DOY", "DATE_TRUNC", "INTERVAL"))

Learn more Showing 3 files with coverage changes found.

Changes in R/backend-.R
New
Loading file...
Changes in R/verb-slice.R
+2
Loading file...
New file R/backend-postgres-old.R
New
Loading file...
Files Coverage
R -0.51% 86.35%
Project Totals (73 files) 86.35%
Loading