Convert a SQLite database schema to DBML so you can visualize it in tools like dbdiagram.io.
No dependencies: just Python 3 and the standard-library sqlite3 module. The database is opened read-only.
python sqlite_to_dbml.py <db_path> <output.dbml>Example:
python sqlite_to_dbml.py app.db schema.dbmlThen paste the contents of schema.dbml into dbdiagram.io to see the diagram.
For each user table (internal sqlite_% tables are skipped):
- A
Tableblock with its columns and types pk,not nullanddefault:annotations fromPRAGMA table_infoRef:lines for each foreign key fromPRAGMA foreign_key_list
Example output:
Table users {
id INTEGER [pk, not null]
email TEXT [not null]
created_at TEXT [default: `CURRENT_TIMESTAMP`]
}
Table posts {
id INTEGER [pk, not null]
user_id INTEGER [not null]
title TEXT
}
Ref: posts.user_id > users.id
from sqlite_to_dbml import convert_to_dbml
convert_to_dbml("app.db", "schema.dbml")- Tables only: views, indexes and
unique/checkconstraints are not exported - Composite foreign keys are emitted as one
Refline per column