Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncruces/sqlite-schema-diagram
https://github.com/ncruces/sqlite-schema-diagram
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ncruces/sqlite-schema-diagram
- Owner: ncruces
- License: agpl-3.0
- Created: 2024-03-23T15:14:28.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-19T15:56:45.000Z (6 months ago)
- Last Synced: 2024-05-19T16:58:00.923Z (6 months ago)
- Language: Makefile
- Homepage: https://gitlab.com/Screwtapello/sqlite-schema-diagram
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
SQLite Schema Diagram Generator
===============================![An example schema diagram](example/schema.svg)
A properly normalised database
can wind up with a lot of small tables
connected by a complex network of foreign key references.
Like a real-world city,
it's pretty easy to find your way around once you're familiar,
but when you first arrive it really helps to have a map.Lots of database management tools include some kind of schema diagram view,
either automatically generated
or manually editable so you can get the layout just right.
But it's usually part of a much bigger suite of tools,
and sometimes I don't want to install a tool,
I just want to get a basic overview quickly.What you need
-------------- The `sqlite3` command-line tool, version 3.37.0 or higher
- The [sqlite-schema-diagram.sql](sqlite-schema-diagram.sql) file
in this repository
- The [GraphViz](https://www.graphviz.org/) graph rendering tool,
avaliable from any Linux distro
and a million other places besidesSQLite version 3.37.0 added the `table_list` pragma,
which we need in order to do this in pure SQL.How it works
------------The [sqlite-schema-diagram.sql](sqlite-schema-diagram.sql) file
contains a query which returns a sequence of strings,
representing a SQLite database's schema in GraphViz format.
You can save it to a file,
or just pipe it to the GraphViz `dot` command
to convert it to your favourite output format: PNG, SVG, PDF, whatever.sqlite3 path/to/database.db -init sqlite-schema-diagram.sql "" > schema.dot
dot -Tsvg schema.dot > schema.svg**Note:** `sqlite3` is invoked with the `-init` option
that tells it to read a file at startup,
and an empty query string that makes it start up in non-interactive mode.
That turns off any extra output formatting `sqlite3` might do
that would interfere with the GraphViz syntax.An example
----------In the [example/](./example/) directory,
you'll find:- An [SQL file](./example/schema.sql) defining a database schema
- A [Makefile](./example/Makefile) that loads it into an SQLite database
and generates a schema diagram
- The [generated schema diagram](./example/schema.svg)
(also at the top of this README)