The sqlite module provides SQLite database integration for Project Forge applications. This module extends the base database module with SQLite-specific functionality, offering an embedded database solution perfect for development, testing, and lightweight production deployments.
Overview
This module adds SQLite embedded database support to Project Forge applications and requires the database module. It provides:
Embedded Database: Zero-configuration embedded database with no external dependencies
File-Based Storage: Single-file database storage with backup and portability
Development-Friendly: Perfect for development, testing, and prototyping
Production-Ready: Suitable for lightweight production applications
Key Features
Embedded Database
No external database server required
Single-file database storage
Zero-configuration setup
Cross-platform compatibility
Performance
In-process database access (no network overhead)
WAL mode for improved concurrency
Connection pooling for multi-threaded access
Optimized for read-heavy workloads
Portability
Single file contains entire database
Easy backup and migration
Version control friendly (for small databases)
Platform-independent database files
Development Benefits
Instant setup for new projects
No database server installation required
Perfect for unit testing and CI/CD
Simplified deployment process
Configuration
Environment Variables
The module reads configuration from environment variables (with optional prefix):
db_file - SQLite database file path (relative to project root)
// In-memory database for testing params:=&SQLiteParams{ File:":memory:", Debug:true, } db,err:=database.OpenSQLiteDatabase(params)
With Environment Prefix
1 2 3
// Use custom environment variable prefix // Reads myapp_db_file, myapp_db_schema, etc. params:=SQLiteParamsFromEnv("myapp_")
SQLite-Specific Features
WAL Mode
SQLite databases automatically use WAL mode for better concurrency:
WAL mode is enabled automatically
Allows concurrent readers with single writer
Better performance for web applications
JSON Support
Modern SQLite includes JSON1 extension:
1 2 3 4 5 6 7 8
// Insert JSON data _,err:=db.Exec(`insert into users (data) values (?)`,`{"name": "John", "preferences": {"theme": "dark"}}`) // Query with JSON functions rows,err:=db.Query(`select json_extract(data, '$.name') from users`) // JSON array operations rows,err:=db.Query(`select * from users where json_extract(data, '$.active') = 'true'`)
Full-Text Search
SQLite’s FTS5 extension provides powerful text search:
1 2 3 4 5
// Create FTS table _,err:=db.Exec(`create virtual table posts_fts using fts5(title, content)`) // Full-text search rows,err:=db.Query(`select * from posts_fts where posts_fts match 'database and sqlite'`)