Skip to contents

Returns a data frame describing the columns of a database table.

Usage

schema_from_db(conn, table, level = c("medium", "low", "high"))

Arguments

conn

A DBI connection.

table

Character scalar: table name to introspect.

level

Privacy preset to annotate in schema metadata: one of "low", "medium", "high". Default "medium".

Value

A data.frame with column metadata (e.g., name, type).

Examples

if (requireNamespace("DBI", quietly = TRUE) &&
    requireNamespace("RSQLite", quietly = TRUE)) {
  con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  on.exit(DBI::dbDisconnect(con), add = TRUE)
  DBI::dbWriteTable(con, "mtcars", mtcars[1:3, ])
  sc <- schema_from_db(con, "mtcars")
  head(sc)
}
#>   name    type nullable sensitive
#> 1  mpg numeric     TRUE     FALSE
#> 2  cyl numeric     TRUE     FALSE
#> 3 disp numeric     TRUE     FALSE
#> 4   hp numeric     TRUE     FALSE
#> 5 drat numeric     TRUE     FALSE
#> 6   wt numeric     TRUE     FALSE