Guide · Tools

SQLite

Browse and edit SQLite databases with a tap, or use the sqlite3 shell in the terminal. Django's db.sqlite3 works the same as any other database.

The database browser

Tap a database in the file tree and it opens in the database browser instead of the editor. Pythilo recognises a SQLite file by its contents, so db.sqlite3, app.db or a database with any other name all open there. At the top, pick a table (each shows its row count) and one of three views: Data, Schema and SQL. The Database actions menu has Reload, Open in the terminal (which runs sqlite3 on the file) and Share file.

A new Django project has no tables until you migrate. The browser says so: create one in the SQL tab, or run python manage.py migrate.

Data: rows, filter and editing

Edits are written to the file straight away. Commit the database with Git first if you may want to undo. Views, and tables created WITHOUT ROWID, are shown read-only.

Schema

Each column with its type, a key for the primary key, and NOT NULL where it applies, followed by the table's CREATE statement.

SQL

Write any SQL and tap Run. A query shows its rows (up to the first 1000) and how many there were; any other statement says how many rows it changed.

sqlite3 in the terminal

The sqlite3 command works like the SQLite shell on a computer, built on Python's sqlite3 module:

sqlite3 db.sqlite3                      # interactive shell; .quit leaves
sqlite3 db.sqlite3 "select count(*) from notes_note"
sqlite3 -box db.sqlite3 "select * from notes_note limit 5"
sqlite3 db.sqlite3 < schema.sql         # run a script

Options: -header, -noheader, the output modes -csv, -json, -line, -list, -column, -box, -table, -markdown and -tabs, plus -separator, -nullvalue, -readonly, -cmd, -bail and -version. It works in pipes and with redirects, like any other command.

Dot commands

CommandDoes
.tables, .schema, .indexesList tables, show CREATE statements, list indexes
.headers on|off, .mode MODEColumn names; list, csv, json, line, column, box, table, markdown or tabs output
.separator, .nullvalueThe separator for list mode, and the text shown for NULL
.read FILE, .import FILE TABLERun SQL from a file; load a CSV file into a table, creating it if missing
.dump, .output FILE, .once FILESQL that recreates the database; send results to a file
.open FILE, .databasesOpen another database; list attached ones
.timer, .changes, .showTime statements, count changed rows, show the settings
.help, .quitHelp, and leave

From Python

Python's own sqlite3 module works in every project, and Django uses SQLite for its database out of the box. python manage.py dbshell is not available, because it starts an external program; use sqlite3 db.sqlite3 instead.

Database files are left out of shared rooms: a room carries source and text files only.