schema_from_db: Extract a table schema from a DB connection

View source: R/sql_schema.R

schema_from_dbR Documentation

Extract a table schema from a DB connection

Description

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)
}


FakeDataR documentation built on Nov. 6, 2025, 1:15 a.m.