Ledger

SQLite Store

Lightweight SQLite store for development, testing, and single-node Ledger deployments.

The store/sqlite package implements Ledger's store.Store interface using the grove ORM with the SQLite driver. It requires no external database process, making it ideal for development, integration tests, and single-node deployments.

Setup

import (
    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/sqlitedriver"
    "github.com/xraph/ledger"
    "github.com/xraph/ledger/store/sqlite"
)

db, err := grove.Open(sqlitedriver.Open("ledger.db"))
if err != nil {
    log.Fatal(err)
}

s := sqlite.New(db)

engine := ledger.New(s,
    ledger.WithMeterConfig(100, 5*time.Second),
)

// Start runs migrations automatically
if err := engine.Start(ctx); err != nil {
    log.Fatal(err)
}
defer engine.Stop()

Pass ":memory:" for a fully in-process, zero-persistence store useful in tests:

db, err := grove.Open(sqlitedriver.Open(":memory:"))

Migrations

Migrations run automatically when engine.Start() is called. For manual control:

if err := s.Migrate(ctx); err != nil {
    log.Fatal(err)
}

Migrations are idempotent -- safe to run on every startup.

Implements store.Store

// Compile-time check
var _ store.Store = (*Store)(nil)

Characteristics

AspectDetail
Drivergrove ORM + sqlitedriver
Migrationsgrove orchestrator with programmatic migrations
TransactionsSQLite-level transactions
ConcurrencyMultiple readers, single writer (WAL mode)
PersistenceFile-based or in-process (":memory:")

When to use

  • Development and local testing without external dependencies.
  • Single-process or embedded billing deployments.
  • CI pipelines where spinning up PostgreSQL is impractical.

On this page