SQLite
A small, fast SQL database that lives in a single file inside the app, with no server to install or run.
- Type
- Embedded relational database
- Created by
- D. Richard Hipp, in the public domain
- Stored as
- A single file on the device
- In my stack
- Offline storage in mobile apps
What it is
Most databases are servers that applications connect to over a network. SQLite is a library built into the application itself, and the whole database is one file. It still speaks real SQL, with tables, indexes, transactions and JSON functions, and it is extremely reliable: it ships inside every iPhone and Android phone, every major browser and countless other programs.
Because there is no network between the app and its data, queries are very fast, and everything works the same with or without a connection. That makes it the natural choice for storing data on a phone, when the app must keep working in a basement, on a remote site or on a plane.
Why I use it
Offline by design. Data is written to the phone first, so field teams can work for hours or days without a signal and lose nothing.
Real SQL on the device. Filtering, sorting and searching inspections works offline with proper queries and indexes, not by loading everything into memory.
Safe writes. Transactions mean an inspection is saved completely or not at all, even if the battery dies mid-save.
Nothing to operate. No server, no configuration, no credentials: it simply ships with the app.
Where I use it
SQLite is at the heart of the offline-first approach in the HR management system. The React Native app saves every clock-in, leave request and form to SQLite on the device first, so nobody waits for a network. Each record knows whether it has been synced yet, and when the connection comes back, the app sends what is pending to the Go backend, which stores it in PostgreSQL.
Best use cases
- Offline-first mobile apps: inspections, audits, deliveries, data collection.
- Local caches that make an app fast and usable on a poor connection.
- Desktop apps and tools that need a reliable local database.
- Small websites and internal tools with modest traffic, where one file is easier to run and back up than a database server.
When I’d use something else
When many users write to the same data at the same time on a server, a client-server database like PostgreSQL handles concurrency, permissions and replication far better. SQLite is the local copy that keeps the app working; the shared source of truth lives on the server.
A small example
The local side of an offline app: a table that remembers what hasn’t been synced yet, and queries the app runs without any network.
-- Faster, safer writes on the phone
PRAGMA journal_mode = WAL;
CREATE TABLE IF NOT EXISTS inspections (
id TEXT PRIMARY KEY, -- UUID created on the device
data TEXT NOT NULL, -- the inspection, as JSON
updated_at TEXT NOT NULL, -- when it changed on the device
synced INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS pending ON inspections (updated_at) WHERE synced = 0;
-- What still has to go to the server, oldest first
SELECT id, data FROM inspections WHERE synced = 0 ORDER BY updated_at;
-- Search inside the JSON, with no network at all
SELECT id FROM inspections WHERE json_extract(data, '$.status') = 'open';