Documentation
¶
Overview ¶
Package consumption contains storage backends for recent tea consumption events.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilDB = errors.New("pg consumption: nil db")
ErrNilDB is returned when the PGStore has not been initialized with a database handle.
Functions ¶
Types ¶
type Consumption ¶
Consumption represents a single tea consumption event.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is a simple in-memory implementation of Store. It is process-local and not persisted across restarts.
func NewMemoryStore ¶
func NewMemoryStore(retention time.Duration) *MemoryStore
type PGStore ¶ added in v1.4.5
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is a PostgreSQL-backed implementation of Store. It expects the schema defined in db/schema.sql (table: consumptions) and delegates SQL execution to code generated by sqlc (pkg/pgstore).
func NewPGStore ¶ added in v1.4.5
NewPGStore creates a PostgreSQL-backed consumption store with the given retention window. If retention <= 0, a default of 30 days is used.
type Store ¶
type Store interface {
Record(ctx context.Context, userID uuid.UUID, teaID uuid.UUID, ts time.Time) error
// Recent returns consumptions since the provided time (inclusive) for the given user.
Recent(ctx context.Context, userID uuid.UUID, since time.Time) ([]Consumption, error)
}
Store defines operations for recording and querying recent tea consumption.