Overview
SQLite is a self-contained, serverless, zero-configuration SQL database engine. Zequel provides full support for SQLite through thebetter-sqlite3 driver (v11.6.0).
Supported Versions
- SQLite 3.25+
- SQLite 3.35+
- SQLite 3.40+
- SQLite 3.44+
- SQLite 3.45+
Connection
File-Based Connection
SQLite databases are single files:.db.sqlite.sqlite3.db3
In-Memory Databases
Create temporary databases that exist only in RAM:In-memory databases are destroyed when the connection closes. They’re useful for testing and temporary data processing.
Features
Tables & Views
- Create, alter, and drop tables
- Create and drop views
- Table and column metadata
- No table comments (not supported by SQLite)
Data Types
SQLite uses dynamic typing with type affinity:- Storage Classes
- Type Affinities
- Common Types
- NULL
- INTEGER
- REAL
- TEXT
- BLOB
SQLite accepts any type name but converts it to one of the five storage classes based on affinity rules.
Indexes
- Create unique and non-unique indexes
- Multi-column indexes
- Partial indexes with WHERE clause
- Drop indexes
Constraints
- Primary keys: Single or composite
- Foreign keys: WITH referential actions (must enable with PRAGMA)
- Unique constraints
- NOT NULL constraints
- CHECK constraints
- DEFAULT values
Auto-Increment
SQLite provides AUTOINCREMENT for INTEGER PRIMARY KEY:Triggers
- Timing: BEFORE, AFTER, INSTEAD OF
- Events: INSERT, UPDATE, DELETE
- Scope: FOR EACH ROW
- Conditions: Optional WHEN clause
Transactions
Full ACID transaction support:SQLite-Specific Features
PRAGMA Statements
Configure database settings:journal_mode = WAL for better concurrency.
JSON Support (SQLite 3.38+)
Query and manipulate JSON data:Full-Text Search (FTS5)
Create full-text search indexes:Attached Databases
Attach multiple database files:Limitations
Schema Limitations
- No ALTER COLUMN: Cannot modify column type or constraints
- Workaround: Create new table, copy data, drop old table, rename
- Zequel automates this process for you
- No DROP COLUMN (before 3.35.0)
- SQLite 3.35+ supports DROP COLUMN
- Limited ALTER TABLE: Cannot add PRIMARY KEY, UNIQUE, or FOREIGN KEY after table creation
- No stored procedures or functions: SQLite doesn’t support user-defined routines
- No user management: File-based permissions only
Concurrency Limitations
- Single writer: Only one write transaction at a time
- Multiple readers: Many concurrent reads allowed (especially with WAL mode)
- No parallel queries: Single-threaded execution
WAL (Write-Ahead Logging) mode significantly improves concurrency by allowing reads during writes.
Data Type Limitations
- No native DATE/TIME types (stored as TEXT or INTEGER)
- No native BOOLEAN type (stored as 0/1)
- Dynamic typing can lead to type confusion
Best Practices
-
Enable WAL mode for better concurrency
-
Enable foreign keys if you use them
-
Use transactions for multiple operations
-
Regular VACUUM to reclaim space
-
Use AUTOINCREMENT sparingly
- Regular INTEGER PRIMARY KEY is faster
- Only use AUTOINCREMENT if you need monotonic IDs
-
Optimize queries with EXPLAIN QUERY PLAN
File Associations
Zequel automatically associates with SQLite database files:.db.sqlite.sqlite3
Docker Development
Zequel includes a pre-built SQLite database for testing:- Tables with various data types
- Views and triggers
- Indexes and constraints
- Foreign key relationships
- FTS5 full-text search table
Performance Tips
- Create indexes on frequently queried columns
- Use prepared statements for repeated queries
- Batch inserts in transactions (1000x faster)
- Analyze tables periodically
- Set optimal cache size based on available RAM