db.schema and 'sqlite-utils schema' command, closes #268

This commit is contained in:
Simon Willison 2021-06-11 13:51:49 -07:00
commit 0d2e4f49f3
6 changed files with 90 additions and 2 deletions

View file

@ -348,6 +348,19 @@ It defaults to showing triggers for all tables. To see triggers for one or more
The command takes the same format options as the ``tables`` and ``views`` commands.
.. _cli_schema:
Showing the schema
==================
The ``sqlite-utils schema`` command shows the full SQL schema for the database::
$ sqlite-utils schema dogs.db
CREATE TABLE "dogs" (
[id] INTEGER PRIMARY KEY,
[name] TEXT
);
.. _cli_analyze_tables:
Analyzing tables

View file

@ -297,6 +297,21 @@ If the record does not exist a ``NotFoundError`` will be raised:
except NotFoundError:
print("Dog not found")
.. _python_api_schema:
Showing the schema
==================
The ``db.schema`` property returns the full SQL schema for the database as a string::
>>> db = sqlite_utils.Database("dogs.db")
>>> print(db.schema)
>>> print(db.schema)
CREATE TABLE "dogs" (
[id] INTEGER PRIMARY KEY,
[name] TEXT
);
.. _python_api_creating_tables:
Creating tables