Document your SQLite tables and columns with in-line comments

Overview

sqlite-docs

A SQLite extension, CLI, and library for documentating SQLite tables, columns, and extensions.

Warning

sqlite-docs is still young and not fully developed. Watch this repo or subscribe to my newsletter for updates. Also consider sponsoring my work if you want this project to release earlier!

sqlite-docs work with "SQLite doc comments" inside CREATE TABLE statements, similar to Rust doc comments, Go Doc Comments, and JSDoc.

Single-line comments that start with an exclamation point (--!) are comments and descriptions for the entire table. Single line comments that start with a dash (---) are comments and description for the following column.

create table students(
  --! All students that attend Foo University. One row per enrolled
  --! student, active and historial.

  --- ID assigned to the student at orientation.
  --- @details https://foo.edu/students/id-format.html
  --- @example 'S10483'
  student_id text primary key,

  --- Full name of the student, includes first and last name.
  --- @example 'Alex Garcia'
  name text,

  --- Birthday of the student, in YYYY-MM-DD format.
  --- @example '1970-01-01'
  birthdate date,

  --- Number of course units the student has completed, since
  -- the last completed academic quarter.
  -- @example 62.5
  completed_units float
);

Once the tables in your database are documented, you can use the sqlite-docs CLI to generate documentation in different formats. Here's an example of generating a markdown data dictionary file:

sqlite-docs generate-markdown my.db -o README.md

Or a Datasette metadata.json:

sqlite-docs generate-datasette my.db -o metadata.json
datasette my.db --metadata metadata.json

You'll then find the table and column descriptions in a few places in Datasette's UI.

Specification

SQLite doc comments support a few "tags", as denoted by the @ sign at the beginning of the comment. These include:

Tag Supported for Description
@example Columns A SQLite literal of an example non-null value the column can contain.
@value Columns A possible non-null value that a column could be. Meant to exhaustively list all enum options a column has
@details Columns, Tables A link or instructions to find more information about the format/contents of a column, such as ID formats, datetime formats, etc.
@source Tables A link or instructions to the raw source of the data backing at able.
@schema Columns

Limitations

No ALTER TABLE support

SQLite will by persist comments in CREATE TABLE statements, in the sqlite_master table.

However, some ALTER TABLE statements will erase or modify these comments, such as with ALTER TABLE x ADD COLUMN, ALTER TABLE x REMOVE COLUMN, and more.

If you think your table will need ALTER TABLE statements in the future, then know that sqlite-docs comments may break. You can always create a new table with your new schema, import data from the old table to the new one, then delete the old table.

sqlite-docs tools use a weak parser

sqlite-docs uses heuristics and simple line-by-line analysis to extract doc comments. It does not fully parse CREATE TABLE statements or use an AST. This means that certain valid SQL will not work with sqlite-docs including:

  • Column names with spaces or newline characters
  • Column definitions that span multiple lines
  • Multi-line comments /* ... */
  • FOREIGN KEY and other constraints

In the far future sqlite-docs will be able to handle all of these cases. If you'd like to see this happen sooner, consider sponsoring my work.

sqlite-docs is early in development

It'll get better and easier to use! sqlite-docs will most likely be distributed as:

  • A CLI for major platforms (MacOS, Linux, Windows etc.)
  • A SQLite extension in the sqlite-ecosystem
  • A Datasette plugin
  • A high-level Python library for parsing indivudal statements
  • A low-level Rust library for parsing individual statements
You might also like...
A scalable, distributed, collaborative, document-graph database, for the realtime web
A scalable, distributed, collaborative, document-graph database, for the realtime web

is the ultimate cloud database for tomorrow's applications Develop easier. Build faster. Scale quicker. What is SurrealDB? SurrealDB is an end-to-end

A programmable document database inspired by CouchDB written in Rust

BonsaiDb Formerly known as PliantDb. Not yet released on crates.io as BonsaiDb. BonsaiDb aims to be a Rust-written, ACID-compliant, document-database

Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.
Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLite.

Description Simple and handy btrfs snapshoting tool. Supports unattended snapshots, tracking, restoring, automatic cleanup and more. Backed with SQLit

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx 🧰 The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

🐸Slippi DB ingests Slippi replays and puts the data into a SQLite database for easier parsing.
🐸Slippi DB ingests Slippi replays and puts the data into a SQLite database for easier parsing.

The primary goal of this project is to make it easier to analyze large amounts of Slippi data. Its end goal is to create something similar to Ballchasing.com but for Melee.

A tool for automated migrations for PostgreSQL, SQLite and MySQL.

Models Models is an implementation for a SQL migration management tool. It supports PostgreSQL, MySQL, and SQLite. Quick Start install the CLI by runn

A Rust-based comment server using SQLite and an intuitive REST API.

soudan A Rust-based comment server using SQLite and an intuitive REST API. Soudan is built with simplicity and static sites in mind. CLI usage See sou

A SQLite extension for quickly generating random numbers, booleans, characters, and blobs

sqlite-fastrandom A SQLite extension for quickly generating random numbers, booleans, characters, and blobs. Not cryptographically secure. Based on sq

Ergonomic bindings to SQLite for Rust

Rusqlite Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres. use rusqlite::{para

Owner
Alex Garcia
freelance software engineer
Alex Garcia
Mycelite is a SQLite extension that allows you to synchronize changes from one instance of SQLite to another.

Mycelite What is Mycelite? Mycelite is a SQLite extension that allows you to synchronize changes from one instance of SQLite to another. Currently, it

Mycelial 16 Jan 2, 2023
Command-line tool to make Rust source code entities from Postgres tables.

pg2rs Command-line tool to make Rust source code entities from Postgres tables. Generates: enums structs which can be then used like mod structs; use

Stanislav 10 May 20, 2022
Extract documentation for the feature flags from comments in Cargo.toml

Document your crate's feature flags This crate provides a macro that extracts documentation comments from Cargo.toml To use this crate, add #![doc = d

Slint 83 Dec 15, 2022
Command-line tool to convert Apple HealthKit data to a SQLite database.

healthkit-to-sqlite Command-line tool to convert Apple HealthKit data to a SQLite database. Getting Started Open the Health app on your iOS device. Cl

Justin Shrake 3 Jan 7, 2023
Grsql is a great tool to allow you set up your remote sqlite database as service and CRUD(create/read/update/delete) it using gRPC.

Grsql is a great tool to allow you set up your remote sqlite database as service and CRUD (create/ read/ update/ delete) it using gRPC. Why Create Thi

Bruce Yuan 33 Dec 16, 2022
Query is a Rust server for your remote SQLite databases and a CLI to manage them.

Query Query is a Rust server for your remote SQLite databases and a CLI to manage them. Table Of Contents Run A Query Server CLI Install Use The Insta

Víctor García 6 Oct 6, 2023
Provides a Rust-based SQLite extension for using Hypercore as the VFS for your databases.

SQLite and Hypercore A Rust library providing SQLite with an virtual file system to enable Hypercore as a means of storage. Contributing The primary r

Jacky Alciné 14 Dec 5, 2022
A programmable document database inspired by CouchDB written in Rust

PliantDB PliantDB aims to be a Rust-written, ACID-compliant, document-database inspired by CouchDB. While it is inspired by CouchDB, this project will

Khonsu Labs 718 Dec 31, 2022
RefineDB - A strongly-typed document database that runs on any transactional key-value store.

RefineDB - A strongly-typed document database that runs on any transactional key-value store.

Heyang Zhou 375 Jan 4, 2023
Simple document-based NoSQL DBMS from scratch

cudb (a.k.a. cuda++) Simple document-based noSQL DBMS modelled after MongoDB. (Has nothing to do with CUDA, has a lot to do with the Cooper Union and

Jonathan Lam 3 Dec 18, 2021