Skip to content

feat: Add Id method to dbExistsTable() - #499

Merged
aviator-app[bot] merged 1 commit into
r-dbi:mainfrom
kjellpk:main
Apr 1, 2024
Merged

aviator-app[bot] merged 1 commit into
r-dbi:mainfrom
kjellpk:main

Conversation

@kjellpk

@kjellpk kjellpk commented Mar 6, 2024 •

Copy link
Copy Markdown
Contributor

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.

@aviator-app

aviator-app Bot commented Mar 6, 2024 •

Copy link
Copy Markdown
Contributor

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

krlmlr commented Mar 6, 2024

Copy link
Copy Markdown
Member

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

krlmlr commented Apr 1, 2024

Copy link
Copy Markdown
Member

Thanks!

@aviator-app
aviator-app Bot merged commit f246f62 into r-dbi:main Apr 1, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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