Skip to contents

Reads the CREATE TABLE statements of a schema and returns one row per column with its type and its comment (-- comment after the column, and continuation lines starting with --). Written once, next to the code that creates the tables, the comments become the data dictionary of the README (schema_markdown()) and of the documentation report, and cannot drift away from the schema.

Usage

schema_dictionary(schema)

Arguments

schema

Named list of CREATE TABLE statements (see create_schema()).

Value

A data.table with table, column, type, description, in the order of the schema.

Examples

schema <- list(
  document = "
    CREATE TABLE IF NOT EXISTS document (
      doc_id   VARCHAR,  -- <source>:<source_id>
      date     DATE,     -- publication date
                         -- (delivery date for speeches)
      year     INTEGER
    )"
)
schema_dictionary(schema)
#>       table column    type                                   description
#>      <char> <char>  <char>                                        <char>
#> 1: document doc_id VARCHAR                          <source>:<source_id>
#> 2: document   date    DATE publication date (delivery date for speeches)
#> 3: document   year INTEGER