Ledger
1.x
Docs/Ledger/SQLite Store
Open

Reading1 min
Updated31 Jul 2026
Sourcev1/stores/sqlite.mdx

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.

Setup01

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:"))

Migrations02

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.Store03

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

Characteristics04

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 use05

  • Development and local testing without external dependencies.

  • Single-process or embedded billing deployments.

  • CI pipelines where spinning up PostgreSQL is impractical.