summaryrefslogtreecommitdiff
path: root/internal/store/annotation.go
diff options
context:
space:
mode:
authorspiperac <[email protected]>2026-06-15 06:42:13 +0200
committerspiperac <[email protected]>2026-06-15 06:42:13 +0200
commit0a477fd288d064d265395c88dbd0f261b723804e (patch)
tree9b129f8f41c907285b89ed8385679934bb59c14f /internal/store/annotation.go
Initial release
Diffstat (limited to 'internal/store/annotation.go')
-rw-r--r--internal/store/annotation.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/store/annotation.go b/internal/store/annotation.go
new file mode 100644
index 0000000..84b0c48
--- /dev/null
+++ b/internal/store/annotation.go
@@ -0,0 +1,58 @@
+package store
+
+import "fmt"
+
+// Annotation holds optional comment and highlight colour for a history row.
+type Annotation struct {
+ HistoryID uint64
+ Comment string
+ Color string // empty means no highlight; one of: "red", "orange", "yellow", "green", "blue", "purple"
+}
+
+// SetAnnotation creates or replaces the annotation for the given history row.
+func (s *Store) SetAnnotation(a Annotation) error {
+ return s.write(func() error {
+ _, err := s.db.Exec(`
+ INSERT INTO annotations (history_id, comment, color)
+ VALUES (?, ?, ?)
+ ON CONFLICT(history_id) DO UPDATE SET
+ comment = excluded.comment,
+ color = excluded.color`,
+ a.HistoryID, a.Comment, a.Color,
+ )
+ if err != nil {
+ return fmt.Errorf("store: set annotation %d: %w", a.HistoryID, err)
+ }
+ return nil
+ })
+}
+
+// DeleteAnnotation removes the annotation for the given history row.
+func (s *Store) DeleteAnnotation(historyID uint64) error {
+ return s.write(func() error {
+ _, err := s.db.Exec(`DELETE FROM annotations WHERE history_id = ?`, historyID)
+ if err != nil {
+ return fmt.Errorf("store: delete annotation %d: %w", historyID, err)
+ }
+ return nil
+ })
+}
+
+// AllAnnotations returns every annotation row. Called once at startup to
+// populate the in-memory annotation map.
+func (s *Store) AllAnnotations() ([]Annotation, error) {
+ rows, err := s.db.Query(`SELECT history_id, comment, color FROM annotations`)
+ if err != nil {
+ return nil, fmt.Errorf("store: all annotations: %w", err)
+ }
+ defer rows.Close()
+ var out []Annotation
+ for rows.Next() {
+ var a Annotation
+ if err := rows.Scan(&a.HistoryID, &a.Comment, &a.Color); err != nil {
+ return nil, fmt.Errorf("store: scan annotation: %w", err)
+ }
+ out = append(out, a)
+ }
+ return out, rows.Err()
+}