tests/testthat/test-backend-postgres-old.R

test_that("RPostgreSQL backend", {
  skip_if_not(identical(Sys.getenv("GITHUB_POSTGRES"), "true"))

  src <- withr::local_db_connection(
    DBI::dbConnect(
      RPostgreSQL::PostgreSQL(),
      dbname = "test",
      user = "postgres",
      password = "password",
      host = "127.0.0.1"
    )
  )

  copy_to(src, mtcars, "mtcars", overwrite = TRUE, temporary = FALSE)
  withr::defer(DBI::dbRemoveTable(src, "mtcars"))

  expect_identical(colnames(tbl(src, "mtcars")), colnames(mtcars))

  src_cyl <- tbl(src, "mtcars") %>% select(cyl) %>% collect()
  expect_identical(src_cyl$cyl, mtcars$cyl)
})

Try the dbplyr package in your browser

Any scripts or data that you put into this service are public.

dbplyr documentation built on Oct. 26, 2023, 9:06 a.m.