What Is SQLite?
SQLite is a small, fast database engine that runs inside your application.
There is usually no server to install, no ports to open, and no admin user to configure. Your app links to SQLite like a normal library.
Core Concepts
Embedded, Serverless, File-Based
flowchart TD
A[Your App Process] --> B[SQLite library]
B --> C[SQL engine]
C --> D[Storage engine]
D --> E[(database.db file)]
What SQLite Gives You
| Feature | What it means in practice | Why you care |
|---|---|---|
| Transactions (ACID) | Changes are all-or-nothing | Prevents partial writes |
| Single-file database | Data lives in one portable file | Easy deployment and backup |
| Cross-platform | Same file format everywhere | Great for apps shipped to users |
| Mature SQL engine | SELECT queries are optimized and reliable | Predictable performance |
Code Examples
SQLite values have a runtime storage class. This is one reason SQLite feels "more flexible" than some databases.
-- typeof() shows the storage class of each value.
-- This is SQLite-specific and does not require any tables.
SELECT
typeof(123) AS t_integer,
typeof(123.0) AS t_real,
typeof('123') AS t_text,
typeof(NULL) AS t_null;
| t_integer | t_real | t_text | t_null |
|---|---|---|---|
| integer | real | text | null |
SQLite-Specific Nuances
SQLite uses dynamic typing with type affinity.
- A column's declared type influences how values are stored and compared
- But the type system is not as strict as many client/server databases
Later, you'll see how constraints help you keep data clean even with SQLite's flexibility.
Common Pitfalls / Best Practices
Assuming SQLite automatically provides user accounts, roles, and permissions.
SQLite typically relies on file permissions plus application-level access control.
Treat the database file as important application data:
- Put it in an appropriate app data directory
- Back it up
- Avoid editing it with non-database tools
Quick Challenge
Without running anything, predict the output of:
SELECT typeof(1 + 1) AS t;
View Solution
SQLite evaluates 1 + 1 as an integer.
SELECT typeof(1 + 1) AS t;
| t |
|---|
| integer |