db

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package db opens Peen's SQLite database, applies its embedded migrations, and wires the generated gorm/gen repositories. Business code uses the typed repository layer rather than a raw database handle.

Index

Constants

View Source
const (
	// MetricsFileName is the observation database under the state directory.
	MetricsFileName = "metrics.db"
)

Variables

This section is empty.

Functions

func DatabaseFiles added in v0.44.0

func DatabaseFiles(stateDirectory string) map[string]string

DatabaseFiles names every SQLite file under the state directory by its role.

Types

type Config

type Config struct {
	Directory   string
	InMemory    bool
	BusyTimeout time.Duration
	Metrics     *metrics.Metrics
	// ContentBlobs, when set, makes workflow storage compact the payloads it
	// encodes into this blob store. Peen's runtime always sets it.
	ContentBlobs contentblob.Store
}

Config identifies the private directory and SQLite connection behavior.

type ContentBlobStore added in v0.26.3

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

ContentBlobStore keeps the long strings of compacted durable state in the session database. See package contentblob.

func (*ContentBlobStore) GetContentBlobs added in v0.26.3

func (s *ContentBlobStore) GetContentBlobs(
	ctx context.Context,
	hashes []string,
) (map[string][]byte, error)

GetContentBlobs returns the stored blobs for the requested hashes. A hash that is not stored is left out.

func (*ContentBlobStore) PutContentBlobs added in v0.26.3

func (s *ContentBlobStore) PutContentBlobs(
	ctx context.Context,
	blobs []contentblob.Blob,
) error

PutContentBlobs stores blobs. Storing a blob that is already stored is a no-op. Every blob must be one string literal whose bytes match its hash, so no caller can store text under a hash it does not own.

type Handle

type Handle struct {
	GormDB *gorm.DB

	// Workflows shares the handle's lifetime when runtime assembly opens it.
	Workflows *WorkflowStorage
	// contains filtered or unexported fields
}

Handle owns an open SQLite connection and its generated GORM query surface.

func Open

func Open(ctx context.Context, cfg Config) (*Handle, error)

Open opens Peen's SQLite store, migrates it, and verifies its integrity.

func (*Handle) Close

func (h *Handle) Close() error

Close releases the database resources held by the handle.

func (*Handle) ContentBlobs added in v0.26.3

func (h *Handle) ContentBlobs() *ContentBlobStore

ContentBlobs returns the blob store of this database.

func (*Handle) SQLDB

func (h *Handle) SQLDB() *sql.DB

SQLDB exposes the infrastructure connection for migration and integrity verification. Request-path code must use generated repositories instead.

type MetricsStorage added in v0.44.0

type MetricsStorage struct {
	Query *repositories.Query
	// contains filtered or unexported fields
}

MetricsStorage owns metrics.db, kept apart from peen.db so telemetry writes never contend with the transcript and the file can be deleted on its own.

func OpenMetricsStorage added in v0.44.0

func OpenMetricsStorage(
	ctx context.Context,
	cfg Config,
) (*MetricsStorage, error)

OpenMetricsStorage opens metrics.db and applies its embedded migrations. The file is disposable, so one whose schema differs from what this build expects is moved aside to metrics.db.stale and a new one takes its place.

func (*MetricsStorage) Close added in v0.44.0

func (s *MetricsStorage) Close() error

Close releases the connection. Repeated calls are safe.

type WorkflowStorage added in v0.25.0

type WorkflowStorage struct {
	backend.Backend
	// contains filtered or unexported fields
}

WorkflowStorage owns the native workflow backend and its SQL connection. Its schema is separate from Peen's pinned session schema.

func OpenWorkflowStorage added in v0.25.0

func OpenWorkflowStorage(
	ctx context.Context,
	cfg Config,
) (*WorkflowStorage, error)

OpenWorkflowStorage prepares private SQLite storage and applies the native workflow backend's migrations. Startup errors are returned to the caller.

func (*WorkflowStorage) Close added in v0.25.0

func (s *WorkflowStorage) Close() error

Close releases the caller-owned SQL connection. Repeated calls are safe.

func (*WorkflowStorage) WorkerBackend added in v0.25.0

func (s *WorkflowStorage) WorkerBackend(
	ctx context.Context,
	generationID uuid.UUID,
) (diag.Backend, error)

WorkerBackend binds native task leases to one worker generation. The controller keeps the SQL connection; closing this borrowed backend does not close durable storage or apply migrations again.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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