tidyverse / dbplyr
Showing 2 of 4 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,24 +24,17 @@
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 -
# Use dbplyr edition 1 for custom method dispatch on RPostgreSQL connections
30 29
#' @export
31 -
dbplyr_edition.PostgreSQLConnection <- function(con) {
32 -
  1L
33 -
}
34 -
#' @export
35 -
dbplyr_edition.PostgreSQL <- dbplyr_edition.PostgreSQLConnection
36 -
37 -
# Use dbplyr edition 2 for RPostgres connections
38 -
#' @export
39 -
dbplyr_edition.PqConnection <- function(con) {
30 +
dbplyr_edition.PostgreSQL <- function(con) {
40 31
  2L
41 32
}
33 +
#' @export
34 +
dbplyr_edition.PqConnection <- dbplyr_edition.PostgreSQL
42 35
43 36
#' @export
44 -
db_connection_describe.PostgreSQLConnection <- function(con) {
37 +
db_connection_describe.PqConnection <- function(con) {
45 38
  info <- dbGetInfo(con)
46 39
  host <- if (info$host == "") "localhost" else info$host
47 40
@@ -49,9 +42,7 @@
Loading
49 42
    host, ":", info$port, "/", info$dbname, "]")
50 43
}
51 44
#' @export
52 -
db_connection_describe.PostgreSQL <- db_connection_describe.PostgreSQLConnection
53 -
#' @export
54 -
db_connection_describe.PqConnection <- db_connection_describe.PostgreSQLConnection
45 +
db_connection_describe.PostgreSQL <- db_connection_describe.PqConnection
55 46
56 47
postgres_grepl <- function(pattern, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) {
57 48
  # https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-TABLE
@@ -71,7 +62,7 @@
Loading
71 62
}
72 63
73 64
#' @export
74 -
sql_translation.PostgreSQLConnection <- function(con) {
65 +
sql_translation.PqConnection <- function(con) {
75 66
  sql_variant(
76 67
    sql_translator(.parent = base_scalar,
77 68
      bitwXor = sql_infix("#"),
@@ -218,55 +209,19 @@
Loading
218 209
  )
219 210
}
220 211
#' @export
221 -
sql_translation.PostgreSQL <- sql_translation.PostgreSQLConnection
222 -
#' @export
223 -
sql_translation.PqConnection <- sql_translation.PostgreSQLConnection
212 +
sql_translation.PostgreSQL <- sql_translation.PqConnection
224 213
225 214
#' @export
226 -
sql_expr_matches.PostgreSQLConnection <- function(con, x, y) {
215 +
sql_expr_matches.PqConnection <- function(con, x, y) {
227 216
  # https://www.postgresql.org/docs/current/functions-comparison.html
228 217
  build_sql(x, " IS NOT DISTINCT FROM ", y, con = con)
229 218
}
230 219
#' @export
231 -
sql_expr_matches.PostgreSQL <- sql_expr_matches.PostgreSQLConnection
232 -
#' @export
233 -
sql_expr_matches.PqConnection <- sql_expr_matches.PostgreSQLConnection
234 -
235 -
# DBI methods ------------------------------------------------------------------
236 -
237 -
#' @export
238 -
db_write_table.PostgreSQLConnection <- function(con, table, types, values,
239 -
                                                temporary = TRUE, overwrite = FALSE, ....) {
240 -
241 -
  dbWriteTable(
242 -
    con,
243 -
    name = table,
244 -
    value = values,
245 -
    field.types = types,
246 -
    temporary = temporary,
247 -
    overwrite = overwrite,
248 -
    row.names = FALSE
249 -
  )
250 -
251 -
  table
252 -
}
253 -
254 -
#' @export
255 -
db_query_fields.PostgreSQLConnection <- function(con, sql, ...) {
256 -
  fields <- build_sql(
257 -
    "SELECT * FROM ", sql_subquery(con, sql), " WHERE 0=1",
258 -
    con = con
259 -
  )
260 -
261 -
  qry <- dbSendQuery(con, fields)
262 -
  on.exit(dbClearResult(qry))
263 -
264 -
  dbGetInfo(qry)$fieldDescription[[1]]$name
265 -
}
220 +
sql_expr_matches.PostgreSQL <- sql_expr_matches.PqConnection
266 221
267 222
# http://www.postgresql.org/docs/9.3/static/sql-explain.html
268 223
#' @export
269 -
sql_query_explain.PostgreSQLConnection <- function(con, sql, format = "text", ...) {
224 +
sql_query_explain.PqConnection <- function(con, sql, format = "text", ...) {
270 225
  format <- match.arg(format, c("text", "json", "yaml", "xml"))
271 226
272 227
  build_sql(
@@ -277,8 +232,6 @@
Loading
277 232
  )
278 233
}
279 234
#' @export
280 -
sql_query_explain.PostgreSQL <- sql_query_explain.PostgreSQLConnection
281 -
#' @export
282 -
sql_query_explain.PqConnection <- sql_query_explain.PostgreSQLConnection
235 +
sql_query_explain.PostgreSQL <- sql_query_explain.PqConnection
283 236
284 237
globalVariables(c("strpos", "%::%", "%FROM%", "DATE", "EXTRACT", "TO_CHAR", "string_agg", "%~*%", "%~%", "MONTH", "DOY", "DATE_TRUNC", "INTERVAL"))
285 238
imilarity index 100%
286 239
ename from tests/testthat/test-backend-rpostgresql.R
287 240
ename to tests/testthat/test-backend-postgresql-old.R
Files Coverage
R 86.35%
Project Totals (73 files) 86.35%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading