Skip to content

About

Convert a SQLite database schema to DBML

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

sqlite-to-dbml

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.

Usage

python sqlite_to_dbml.py <db_path> <output.dbml>

Example:

python sqlite_to_dbml.py app.db schema.dbml

Then paste the contents of schema.dbml into dbdiagram.io to see the diagram.

What it generates

For each user table (internal sqlite_% tables are skipped):

  • A Table block with its columns and types
  • pk, not null and default: annotations from PRAGMA table_info
  • Ref: lines for each foreign key from PRAGMA 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

Use as a module

from sqlite_to_dbml import convert_to_dbml

convert_to_dbml("app.db", "schema.dbml")

Limitations

  • Tables only: views, indexes and unique / check constraints are not exported
  • Composite foreign keys are emitted as one Ref line per column

About

Convert a SQLite database schema to DBML

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages