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:
+9
-9
@@ -21,19 +21,19 @@ func init() {
|
||||
rootCmd.AddCommand(editCmd)
|
||||
}
|
||||
|
||||
func runEdit(_ *cobra.Command, args []string) error {
|
||||
func runEdit(cmd *cobra.Command, args []string) error {
|
||||
store, err := openStore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
id, err := store.Resolve(args[0])
|
||||
id, err := store.Resolve(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("not_found — no entity with id %s", args[0])
|
||||
}
|
||||
|
||||
e, err := store.Get(id)
|
||||
e, err := store.Get(cmd.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,11 +55,11 @@ func runEdit(_ *cobra.Command, args []string) error {
|
||||
editor = "vi"
|
||||
}
|
||||
|
||||
cmd := exec.Command(editor, tmpfile.Name())
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
editorCmd := exec.Command(editor, tmpfile.Name())
|
||||
editorCmd.Stdin = os.Stdin
|
||||
editorCmd.Stdout = os.Stdout
|
||||
editorCmd.Stderr = os.Stderr
|
||||
if err := editorCmd.Run(); err != nil {
|
||||
return fmt.Errorf("editor: %w", err)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func runEdit(_ *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := store.Update(id, &db.EntityUpdate{Body: &body}); err != nil {
|
||||
if err := store.Update(cmd.Context(), id, &db.EntityUpdate{Body: &body}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user