Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Id method to dbExistsTable() #499

Merged
merged 1 commit into from
Apr 1, 2024
Merged

Conversation

kjellpk
Copy link
Contributor

@kjellpk kjellpk commented Mar 6, 2024

Add an Id method to dbExistsTable. When a schema is present in the Id, check that schema is the name of an ATTACHed database and return FALSE if not.

I also made some tests but wasn't sure where to put them.

test_that("dbExistsTable works with compound Id", {
  expect_no_error(
    conn <- dbConnect(RSQLite::SQLite(), ":memory:")
  )

  expect_type(
    dbExistsTable(conn, Id(schema = "INFORMATION_SCHEMA",
                           table = "TABLES")),
    "logical"
  )

  expect_no_error(
    dbWriteTable(conn, "Iris", iris)
  )

  expect_true(
    dbExistsTable(conn, Id(schema = "main", table = "Iris"))
  )

  expect_true(
    dbExistsTable(conn, Id(able = "Iris"))
  )

  expect_false(
    dbExistsTable(conn, Id(schema = "mian", table = "Iris"))
  )

  expect_no_error(
    dbCreateTable(conn, "IrisTemp", iris, temporary = TRUE)
  )

  expect_false(
    dbExistsTable(conn, Id(schema = "temp", table = "Iris"))
  )

  expect_true(
    dbExistsTable(conn, Id(schema = "temp", table = "IrisTemp"))
  )

  expect_true(
    dbExistsTable(conn, Id(table = "IrisTemp"))
  )

  expect_no_error(
    dbDisconnect(conn)
  )
})

Closes #498.

Copy link
Contributor

aviator-app bot commented Mar 6, 2024

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@krlmlr
Copy link
Member

krlmlr commented Mar 6, 2024

Thanks. I'll need to review what other dbExistsTable() methods exist, to avoid weird S4 dispatch issues. I also wonder if this should be perhaps handled by DBI, at least in part.

@krlmlr krlmlr changed the title Add Id method to dbExistsTable to address issue #498 feat: Add Id method to dbExistsTable() Apr 1, 2024
@krlmlr
Copy link
Member

krlmlr commented Apr 1, 2024

Thanks!

@aviator-app aviator-app bot merged commit f246f62 into r-dbi:main Apr 1, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dbExistsTable(conn, Id(schema = "INFORMATION_SCHEMA", table = "TABLES")) throws error (should return FALSE?)
2 participants