sqlite

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sqlite provides a SQLite-backed crypto.KeyStore for the synapse event-sourcing toolkit.

Schema:

keys(subject PK, dek BLOB NULL, shredded_at INTEGER NULL)

Shred sets dek = NULL and shredded_at = now(ns). A tombstoned row outlives the key — that's what makes "already shredded" distinct from "never seen" to the keystore implementation. Both surface as crypto.ErrKeyShredded to callers, because they are indistinguishable to a consumer that doesn't hold the key.

The package blank-imports modernc.org/sqlite to register the pure-Go driver. WAL + busy_timeout + _txlock=immediate are strongly recommended for concurrent workloads (see eventstore/sqlite for the full rationale).

Index

Constants

This section is empty.

Variables

View Source
var Schema string

Schema is the SQL DDL this Store requires. It is exported so users who manage migrations externally (goose, golang-migrate, atlas, etc.) can feed it to their own tooling. New applies it by default; WithoutMigrate disables that. Migrate applies it explicitly.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate applies Schema to db. Idempotent (CREATE TABLE IF NOT EXISTS), so repeated calls are safe.

Types

type Option

type Option func(*options)

Option configures New.

func WithoutMigrate

func WithoutMigrate() Option

WithoutMigrate disables the automatic schema migration that New performs by default.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a SQLite-backed crypto.KeyStore.

The caller owns the underlying *sql.DB and is responsible for closing it.

func New

func New(ctx context.Context, db *sql.DB, opts ...Option) (*Store, error)

New returns a Store wrapping db. By default applies Schema; pass WithoutMigrate to skip when migrations are external.

func (*Store) Get

func (s *Store) Get(ctx context.Context, subject string) ([]byte, error)

Get implements crypto.KeyStore. Returns ErrKeyShredded both for tombstoned subjects and for never-seen subjects.

func (*Store) GetOrCreate

func (s *Store) GetOrCreate(ctx context.Context, subject string) ([]byte, error)

GetOrCreate implements crypto.KeyStore. Returns ErrKeyShredded if subject has previously been Shred-ded; otherwise creates a fresh 32-byte DEK on first use and returns the existing one thereafter.

Concurrent first-calls for the same subject race on the unique constraint; the loser falls back to a SELECT and returns the existing row.

func (*Store) Shred

func (s *Store) Shred(ctx context.Context, subject string) error

Shred implements crypto.KeyStore. Idempotent — tombstones the subject row.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL