refactor(db): thread context.Context through all Store methods

Enables request-scoped cancellation, timeouts, and graceful shutdown
for all database operations across API handlers, CLI commands, and TUI.
This commit is contained in:
2026-05-20 20:51:51 -04:00
parent 50b80f4407
commit d715b053e7
18 changed files with 267 additions and 228 deletions
+7 -6
View File
@@ -1,6 +1,7 @@
package cmd
import (
"context"
"encoding/json"
"fmt"
"os"
@@ -35,7 +36,7 @@ type demoEntity struct {
Tags []string `json:"tags"`
}
func runDemo(_ *cobra.Command, _ []string) error {
func runDemo(cmd *cobra.Command, _ []string) error {
tmpDir, err := os.MkdirTemp("", "nib-demo-*")
if err != nil {
return err
@@ -48,7 +49,7 @@ func runDemo(_ *cobra.Command, _ []string) error {
return err
}
if err := seedDemo(store); err != nil {
if err := seedDemo(cmd.Context(), store); err != nil {
store.Close()
return fmt.Errorf("seed demo data: %w", err)
}
@@ -58,7 +59,7 @@ func runDemo(_ *cobra.Command, _ []string) error {
return runServe(nil, nil)
}
func seedDemo(store *db.Store) error {
func seedDemo(ctx context.Context, store *db.Store) error {
data, err := findDemoFile()
if err != nil {
return err
@@ -94,19 +95,19 @@ func seedDemo(store *db.Store) error {
e.CompletedAt = &t
}
if err := store.Create(e); err != nil {
if err := store.Create(ctx, e); err != nil {
return fmt.Errorf("entity %d: %w", i, err)
}
if entry.CardType != nil {
ct := db.CardType(*entry.CardType)
if err := store.Promote(e.ID, ct, entry.CardData); err != nil {
if err := store.Promote(ctx, e.ID, ct, entry.CardData); err != nil {
return fmt.Errorf("promote entity %d: %w", i, err)
}
}
if entry.Deleted {
store.SoftDelete(e.ID)
store.SoftDelete(ctx, e.ID)
}
}