diff options
Diffstat (limited to 'internal/store/store.go')
| -rw-r--r-- | internal/store/store.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/store/store.go b/internal/store/store.go index 19b71b1..c0cdea5 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -560,6 +560,39 @@ func (s *Store) SetRuleEnabled(id int64, enabled bool) error { return nil } +// DeleteEntry removes a single history entry and its search index row. +func (s *Store) DeleteEntry(id int64) error { + tx, err := s.db.Begin() + if err != nil { + return fmt.Errorf("begin delete entry: %w", err) + } + defer tx.Rollback() + if _, err := tx.Exec(`DELETE FROM history WHERE id = ?`, id); err != nil { + return fmt.Errorf("delete history entry %d: %w", id, err) + } + if _, err := tx.Exec(`DELETE FROM history_fts WHERE rowid = ?`, id); err != nil { + return fmt.Errorf("delete search index for entry %d: %w", id, err) + } + return tx.Commit() +} + +// ClearHistory removes every history entry and resets the search index. +// Rules are untouched - this only clears captured traffic. +func (s *Store) ClearHistory() error { + tx, err := s.db.Begin() + if err != nil { + return fmt.Errorf("begin clear history: %w", err) + } + defer tx.Rollback() + if _, err := tx.Exec(`DELETE FROM history`); err != nil { + return fmt.Errorf("clear history: %w", err) + } + if _, err := tx.Exec(`DELETE FROM history_fts`); err != nil { + return fmt.Errorf("clear search index: %w", err) + } + return tx.Commit() +} + // DeleteRule removes a rule. func (s *Store) DeleteRule(id int64) error { if _, err := s.db.Exec(`DELETE FROM rules WHERE id = ?`, id); err != nil { |