store

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested record does not exist.

Functions

This section is empty.

Types

type SQLiteStore

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

SQLiteStore implements Store using an SQLite database.

func New

func New(dbPath string) (*SQLiteStore, error)

New opens (or creates) an SQLite database at dbPath, runs migrations, and enables WAL mode and foreign keys.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the underlying database connection.

func (*SQLiteStore) ComputeCostSince

func (s *SQLiteStore) ComputeCostSince(ctx context.Context, since time.Time) (summary *models.CostSummary, err error)

ComputeCostSince aggregates all cost records created at or after the given time.

func (*SQLiteStore) CreateSession

func (s *SQLiteStore) CreateSession(ctx context.Context, sess *models.Session) error

CreateSession inserts a new session record. If s.ID is empty, a random ID is generated.

func (*SQLiteStore) GetBudgetStatus

func (s *SQLiteStore) GetBudgetStatus(ctx context.Context, dailyBudgetUSD float64) (spent, remaining float64, err error)

GetBudgetStatus computes today's spending and remaining budget. spent is the total cost_usd since midnight UTC today. remaining is dailyBudgetUSD - spent (floored at 0).

func (*SQLiteStore) GetSession

func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*models.Session, error)

GetSession retrieves a session by ID. Returns ErrNotFound if no row matches.

func (*SQLiteStore) ListSessions

func (s *SQLiteStore) ListSessions(ctx context.Context, status models.SessionStatus) ([]*models.Session, error)

ListSessions returns all sessions matching the given status. Pass an empty status to list all sessions.

func (*SQLiteStore) RecordCost

func (s *SQLiteStore) RecordCost(ctx context.Context, r *models.CostRecord) error

RecordCost inserts a cost record. If r.ID is empty, a random ID is generated.

func (*SQLiteStore) UpdateSession

func (s *SQLiteStore) UpdateSession(ctx context.Context, sess *models.Session) error

UpdateSession updates an existing session record. The ID must already exist.

type Store

type Store interface {
	// Sessions
	CreateSession(ctx context.Context, s *models.Session) error
	GetSession(ctx context.Context, id string) (*models.Session, error)
	UpdateSession(ctx context.Context, s *models.Session) error
	ListSessions(ctx context.Context, status models.SessionStatus) ([]*models.Session, error)

	// Cost tracking
	RecordCost(ctx context.Context, r *models.CostRecord) error
	ComputeCostSince(ctx context.Context, since time.Time) (*models.CostSummary, error)
	GetBudgetStatus(ctx context.Context, dailyBudgetUSD float64) (spent float64, remaining float64, err error)

	Close() error
}

Store defines the persistence interface for Samverk.

Jump to

Keyboard shortcuts

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