db

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 28 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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