Connection URL Format
SQLite connections can use either URL format or direct file paths:Path Examples
Geni automatically creates the database file and parent directories if they don’t exist (source:
sqlite.rs:32-38).Setup
Configuration Examples
- Local Development
- Testing
- Production (Embedded)
Features
Transaction Support
SQLite migrations run in transactions by default usingexecute_transactional_batch. To disable transactions:
SQLite has different transaction behavior than server-based databases. Some operations like
PRAGMA statements should run outside transactions.Schema Dumping
Geni automatically dumps your SQLite schema after each successful migration by queryingsqlite_master:
- Tables
- Indexes
- Views
- Triggers
sqlite.rs:176-194).
Automatic File Creation
Unlike server-based databases, SQLite doesn’t need acreate command. Geni automatically:
- Creates parent directories if they don’t exist
- Creates the database file if it doesn’t exist
- Initializes the migrations table
Database Operations
Create Database
Not needed for SQLite. The file is created automatically:Drop Database
sqlite.rs:143-150).
Check Status
Limitations
No Remote Connections
SQLite is file-based and doesn’t support network connections. For remote SQLite-compatible databases, use LibSQL instead.No Ready Check
Since SQLite is file-based, there’s no connection readiness check. Theready() function always returns Ok(()) (source: sqlite.rs:154-157).
No Concurrent Writers
SQLite supports multiple readers but only one writer at a time. For applications needing high write concurrency, consider PostgreSQL or MySQL.Examples
Basic Migration
Create a table in20240115120000_create_users.up.sql:
20240115120000_create_users.down.sql:
SQLite-Specific Features
Using SQLite features:In-Memory Database for Testing
For tests, use an in-memory database:Troubleshooting
File Permissions
If you see permission errors:- Check the database file has write permissions
- Ensure the parent directory exists and is writable
- Verify the process user has access to the file location
Locked Database
If you see “database is locked” errors:- Close any other connections to the database file
- Check for long-running transactions
- Ensure no other processes are writing to the file
- Consider using WAL mode for better concurrency:
Migration Table
Geni creates aschema_migrations table to track applied migrations:
Best Practices
- Use absolute paths in production to avoid ambiguity
- Enable foreign keys with
PRAGMA foreign_keys = ONin migrations - Use WAL mode for better concurrency:
PRAGMA journal_mode = WAL - Keep database files in version control for development (but not production data)
- Use in-memory databases for fast tests
- Set appropriate file permissions for security
When to Use SQLite
Good for:- Development and testing
- Embedded applications
- Mobile apps
- Desktop applications
- Low to medium traffic websites
- Read-heavy workloads
- High write concurrency
- Distributed systems
- Network-based applications requiring remote access
- Applications requiring user permissions at database level