Documentation
¶
Index ¶
- Variables
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) ComputeCostSince(ctx context.Context, since time.Time) (summary *models.CostSummary, err error)
- func (s *SQLiteStore) CreateSession(ctx context.Context, sess *models.Session) error
- func (s *SQLiteStore) GetBudgetStatus(ctx context.Context, dailyBudgetUSD float64) (spent, remaining float64, err error)
- func (s *SQLiteStore) GetSession(ctx context.Context, id string) (*models.Session, error)
- func (s *SQLiteStore) ListSessions(ctx context.Context, status models.SessionStatus) ([]*models.Session, error)
- func (s *SQLiteStore) RecordCost(ctx context.Context, r *models.CostRecord) error
- func (s *SQLiteStore) UpdateSession(ctx context.Context, sess *models.Session) error
- type Store
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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.