Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Connect SQLite

Connect Horizon Epoch to SQLite databases.

CLI Configuration

# File-based database
epoch storage add local \
    --type sqlite \
    --path "/path/to/database.db"

# In-memory database (for testing)
epoch storage add test \
    --type sqlite \
    --path ":memory:"

Configuration Options

OptionDescriptionDefault
journal_modeWAL, DELETE, TRUNCATE, etc.WAL
foreign_keysEnable foreign key enforcementtrue
busy_timeoutLock wait timeout (ms)5000
epoch storage add local \
    --type sqlite \
    --path "/data/mydb.db" \
    --journal-mode wal

Enable Foreign Keys

epoch storage add local \
    --type sqlite \
    --path "/data/mydb.db" \
    --foreign-keys true

Register Tables

epoch table add users \
    --location "sqlite://local/users"

Use Cases

Development/Testing

SQLite is ideal for local development:

# Create a local test database
epoch storage add dev \
    --type sqlite \
    --path "./test.db"

epoch init my-repo --storage dev

Embedded Applications

For applications that need embedded data versioning without external databases.

Edge/Offline

SQLite works well for edge deployments or offline-first applications.

Constraint Support

SQLite has partial constraint support:

ConstraintSupport
Primary KeyFull
UniqueFull
Foreign KeyRequires foreign_keys=true
CheckFull
IndexFull

Foreign keys must be explicitly enabled:

epoch storage add local \
    --type sqlite \
    --path "/data/mydb.db" \
    --foreign-keys true

Troubleshooting

Database Locked

  • Increase busy_timeout for high-concurrency scenarios
  • Use WAL mode for better concurrent access
  • Ensure only one process writes at a time

Foreign Key Violations Not Detected

  • Ensure foreign_keys=true is set
  • Foreign key enforcement is off by default in SQLite

Permission Denied

  • Check file and directory permissions
  • Ensure the directory exists