Keysmith

SQLite Store

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

The store/sqlite package implements Keysmith'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.

Usage

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

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

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

eng, err := keysmith.NewEngine(keysmith.WithStore(s))

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

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

Migrations

The store uses the grove migration orchestrator with programmatic migrations. Run them on startup:

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

This creates seven tables:

TableDescription
keysmith_keysAPI keys with hash, state, and metadata
keysmith_policiesPolicy definitions
keysmith_scopesScope definitions
keysmith_key_scopesKey-scope junction table
keysmith_usagePer-request usage records
keysmith_usage_aggAggregated usage (daily/monthly)
keysmith_rotationsRotation history records

Migrations are idempotent and safe to run on every startup.

Internals

AspectDetail
Drivergrove ORM + sqlitedriver
Migrationsgrove orchestrator with programmatic migrations
TransactionsSQLite-level transactions
ConcurrencyMultiple readers, single writer (WAL mode)
Subsystemskeys, policies, scopes, usages, rotations

Health checks

if err := s.Ping(ctx); err != nil {
    log.Fatal("database unreachable:", err)
}

Usage with the engine

eng, err := keysmith.NewEngine(keysmith.WithStore(s))

When to use

ScenarioRecommended
Unit testsYes
Integration testsYes
Local developmentYes
CI pipelinesYes
Single-node deploymentsYes
Multi-node productionNo -- use PostgreSQL or MongoDB

On this page