store

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotFound

func NotFound(err error) error

Types

type Audit

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

func (*Audit) List

func (s *Audit) List(ctx context.Context, limit int) ([]*AuditEntry, error)

func (*Audit) Log

func (s *Audit) Log(ctx context.Context, userID, action, targetType, targetID string, meta map[string]any) error

type AuditEntry

type AuditEntry struct {
	ID         int64
	UserID     string
	Action     string
	TargetType string
	TargetID   string
	Meta       map[string]any
	CreatedAt  time.Time
}

type Completions

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

func (*Completions) List

func (s *Completions) List(ctx context.Context, userID string, from, to *time.Time, limit int, cursor string) ([]*models.TaskCompletion, string, error)

List returns a user's completions ordered newest-first, filtered to [from, to] on completed_at when provided, with cursor pagination mirroring Tasks.List. It returns the page plus an opaque next-page cursor ("" when the page is the last one).

func (*Completions) ListByDue

func (s *Completions) ListByDue(ctx context.Context, userID string, from, to *time.Time) ([]*models.TaskCompletion, error)

ListByDue returns completions whose occurrence due_at falls in [from, to], used by the calendar to place each finished occurrence on its own due day regardless of when it was actually completed. Capped at maxDueRows.

func (*Completions) TaskIDs

func (s *Completions) TaskIDs(ctx context.Context, userID string) (map[string]bool, error)

TaskIDs returns the set of task ids that have at least one recorded completion, i.e. tasks that are (or were) recurring.

type Sessions

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

func (*Sessions) Create

func (s *Sessions) Create(ctx context.Context, userID, tokenHash, userAgent string, ttl time.Duration) (*models.Session, error)

func (*Sessions) DeleteByUser added in v0.2.0

func (s *Sessions) DeleteByUser(ctx context.Context, userID string) error

DeleteByUser removes every session belonging to a user. Used to invalidate all outstanding cookies after a password change.

func (*Sessions) DeleteExpired

func (s *Sessions) DeleteExpired(ctx context.Context, now time.Time) error

func (*Sessions) Expire

func (s *Sessions) Expire(ctx context.Context, id string) error

func (*Sessions) Lookup

func (s *Sessions) Lookup(ctx context.Context, tokenHash string) (*models.Session, error)

type Store

type Store struct {
	Users       *Users
	Tokens      *Tokens
	Sessions    *Sessions
	Tasks       *Tasks
	Completions *Completions
	Audit       *Audit
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB) *Store

func (*Store) Timeline added in v0.2.0

func (s *Store) Timeline(ctx context.Context, userID, filter string, from, to *time.Time, limit int, cursor string) ([]*TimelineItem, string, error)

Timeline returns a user's task timeline for the given filter (pending|completed|all) with cursor pagination. pending/all are ordered by due date ascending; completed by completion time descending. It unifies open tasks, finished one-off tasks and recurring-task completion occurrences into one ordered, paginated stream, returning the page and an opaque next cursor ("" on the last page). from/to window the sort axis when non-nil.

type Tasks

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

func (*Tasks) Complete

func (s *Tasks) Complete(ctx context.Context, userID, id string, now time.Time, advance func(*models.Task, time.Time) (*models.TaskCompletion, bool, error)) (*models.Task, *models.TaskCompletion, bool, error)

func (*Tasks) Create

func (s *Tasks) Create(ctx context.Context, t *models.Task) error

func (*Tasks) Delete

func (s *Tasks) Delete(ctx context.Context, userID, id string) error

func (*Tasks) Get

func (s *Tasks) Get(ctx context.Context, userID, id string) (*models.Task, error)

func (*Tasks) List

func (s *Tasks) List(ctx context.Context, userID string, f models.TaskFilter) ([]*models.Task, string, error)

func (*Tasks) ListDue

func (s *Tasks) ListDue(ctx context.Context, now time.Time, maxRows int) ([]*models.Task, error)

func (*Tasks) SetLastNotified

func (s *Tasks) SetLastNotified(ctx context.Context, id string, at time.Time) error

func (*Tasks) Update

func (s *Tasks) Update(ctx context.Context, t *models.Task) error

type TimelineItem added in v0.2.0

type TimelineItem struct {
	Kind               TimelineKind
	ID                 string
	TaskID             string
	Title              string
	Priority           models.Priority
	DueAt              time.Time
	CompletedAt        *time.Time
	RecurrenceFreq     *models.RecurrenceFreq
	RecurrenceInterval int
	SnoozedUntil       *time.Time
	Description        string
}

TimelineItem is one row of a unified task timeline.

type TimelineKind added in v0.2.0

type TimelineKind string

TimelineKind distinguishes the three row sources a task timeline mixes.

const (
	TimelinePending    TimelineKind = "pending"        // an open task
	TimelineCompleted  TimelineKind = "completed_task" // a finished one-off task
	TimelineOccurrence TimelineKind = "occurrence"     // a recorded completion of a recurring task
)

type Tokens

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

func (*Tokens) Create

func (s *Tokens) Create(ctx context.Context, userID, name, prefix, hash string) (*models.APIToken, error)

func (*Tokens) Get

func (s *Tokens) Get(ctx context.Context, userID, id string) (*models.APIToken, error)

func (*Tokens) GetByPrefix

func (s *Tokens) GetByPrefix(ctx context.Context, prefix string) (*models.APIToken, error)

GetByPrefix looks up an active (non-revoked) token by its public prefix across all users. Used by the admin CLI's `token revoke --prefix`.

func (*Tokens) List

func (s *Tokens) List(ctx context.Context, userID string) ([]*models.APIToken, error)

func (*Tokens) LookupByHash

func (s *Tokens) LookupByHash(ctx context.Context, hash string) (*models.APIToken, error)

func (*Tokens) Purge

func (s *Tokens) Purge(ctx context.Context, id string) error

func (*Tokens) Revoke

func (s *Tokens) Revoke(ctx context.Context, userID, id string) error

func (*Tokens) Touch

func (s *Tokens) Touch(ctx context.Context, id string) error

type Users

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

func (*Users) ClearTelegramConfig

func (s *Users) ClearTelegramConfig(ctx context.Context, userID string) error

func (*Users) Create

func (s *Users) Create(ctx context.Context, u *models.User) error

func (*Users) GetByEmail

func (s *Users) GetByEmail(ctx context.Context, email string) (*models.User, error)

func (*Users) GetByID

func (s *Users) GetByID(ctx context.Context, id string) (*models.User, error)

func (*Users) GetByTelegramWebhookSecret

func (s *Users) GetByTelegramWebhookSecret(_ context.Context, _ string) (*models.User, error)

func (*Users) GetTelegramConfig

func (s *Users) GetTelegramConfig(ctx context.Context, userID string) (encryptedToken, allowedUserIDs string, chatID, chatUserID string, configuredAt *time.Time, err error)

func (*Users) List

func (s *Users) List(ctx context.Context) ([]*models.User, error)

func (*Users) ListTelegramEnabled

func (s *Users) ListTelegramEnabled(ctx context.Context) ([]*models.User, error)

func (*Users) SetTelegramChatID

func (s *Users) SetTelegramChatID(ctx context.Context, userID, chatID, chatUserID string) error

func (*Users) SetTelegramConfig

func (s *Users) SetTelegramConfig(ctx context.Context, userID, encryptedToken, allowedUserIDs string) error

func (*Users) SoftDelete

func (s *Users) SoftDelete(ctx context.Context, id string) error

func (*Users) Update

func (s *Users) Update(ctx context.Context, u *models.User) error

func (*Users) UpdatePassword

func (s *Users) UpdatePassword(ctx context.Context, userID, hash string) error

Jump to

Keyboard shortcuts

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