Sql File Comment and Statement Parsing for Documentation
This crate extracts documentation from SQL files by parsing:
- SQL statements (via
sqlparser) - Line and block comments
- Table and column locations
It then attaches comments to the SQL structures they describe, producing a structured, queryable documentation model.
Example
With a directory structured like this:
and the content of users.sql being:
/* Table storing user accounts */
(
/* Primary key for each user */
id INTEGER PRIMARY KEY,
-- The user's login name
username VARCHAR(255) NOT NULL,
/* User's email address */
email VARCHAR(255) UNIQUE NOT NULL
);
A rudimentary implementation can be generated with:
use SqlDoc;
use DocError;
use ;
Primary Interface (Main API)
These are the primary entry points most users will interact with:
SqlDoc::from_pathBuild documentation from a single.sqlfile.SqlDoc::from_dirRecursively scan a directory for.sqlfiles and build documentation.SqlDocBuilder::buildFinalize the builder and produce a [SqlDoc].SqlDocBuilder::denyExclude specific files by full path.SqlDocBuilder::flatten_multilineFlatten multiline comments into a single line.
Use Cases
This crate is designed for generating documentation from SQL schemas by attaching comments to:
- Tables
- Columns
using only comments that immediately precede the items they describe.
This makes it well-suited for:
- Auto-generating Markdown or HTML documentation
- Building database schema explorers
- Enforcing documentation rules in CI
- Static analysis of SQL schemas
Design Notes
- Inline and interstitial comments are intentionally ignored.
- Comment attachment is line-based and deterministic.
- One SQL file may define multiple tables.
- No database connection is required.