Skip to content
Latchkey

sqlite3 Command Reference: Flags, Dot-Commands & CI Examples

sqlite3 is the command-line shell for SQLite database files.

sqlite3 opens a SQLite file (or an in-memory database) and runs SQL plus dot-commands. With no server to wait on, it is a lightweight fixture and report engine in CI.

Common flags and usage

  • sqlite3 db.sqlite "SQL": run a statement and exit
  • .read <file>: execute SQL from a file
  • .dump: emit SQL that recreates the database
  • .mode csv / -csv: CSV input and output
  • .import <file> <table>: bulk-load a file into a table
  • -batch / -bail: non-interactive; stop on first error

Example

shell
sqlite3 -bail app.db < schema.sql
sqlite3 -csv app.db 'SELECT id,email FROM users' > users.csv

In CI

Use -bail so a failing statement stops the script and fails the step. sqlite3 .dump produces a portable SQL backup; redirect it to a file to snapshot a fixture database between jobs.

Key takeaways

  • sqlite3 runs SQL and dot-commands against a file or :memory: db.
  • -bail makes a failing statement fail the CI step.
  • .dump exports a portable SQL snapshot of the database.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →