feat(db): add DeleteAllHistory query for batch history removal
- commit
- 551b57d02c507fbddcef5d555192b553c02bb3a9
- author
- bnema · · 2025-11-19 18:24 UTC
- parent
- 696087a
- signature
- GPG Unverified
2B82207D370127A0The key is unknown
4 files · +14 -0
M internal/db/history.sql.go +9 -0
| @@ -25,6 +25,15 @@ func (q *Queries) AddOrUpdateHistory(ctx context.Context, url string, title sql. | |||
| 25 | 25 | return err | |
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | + | const DeleteAllHistory = `-- name: DeleteAllHistory :exec | |
| 29 | + | DELETE FROM history | |
| 30 | + | ` | |
| 31 | + | ||
| 32 | + | func (q *Queries) DeleteAllHistory(ctx context.Context) error { | |
| 33 | + | _, err := q.db.ExecContext(ctx, DeleteAllHistory) | |
| 34 | + | return err | |
| 35 | + | } | |
| 36 | + | ||
| 28 | 37 | const DeleteHistory = `-- name: DeleteHistory :exec | |
| 29 | 38 | DELETE FROM history | |
| 30 | 39 | WHERE id = ? | |
| @@ -25,6 +25,15 @@ func (q *Queries) AddOrUpdateHistory(ctx context.Context, url string, title sql. | |||||
| 25 | return err | 25 | return err | ||
| 26 | } | 26 | } | ||
| 27 | 27 | ||||
| 28 | + | const DeleteAllHistory = `-- name: DeleteAllHistory :exec | |||
| 29 | + | DELETE FROM history | |||
| 30 | + | ` | |||
| 31 | + | ||||
| 32 | + | func (q *Queries) DeleteAllHistory(ctx context.Context) error { | |||
| 33 | + | _, err := q.db.ExecContext(ctx, DeleteAllHistory) | |||
| 34 | + | return err | |||
| 35 | + | } | |||
| 36 | + | ||||
| 28 | const DeleteHistory = `-- name: DeleteHistory :exec | 37 | const DeleteHistory = `-- name: DeleteHistory :exec | ||
| 29 | DELETE FROM history | 38 | DELETE FROM history | ||
| 30 | WHERE id = ? | 39 | WHERE id = ? | ||
M internal/db/interfaces.go +1 -0
| @@ -25,6 +25,7 @@ type HistoryQuerier interface { | |||
| 25 | 25 | AddOrUpdateHistory(ctx context.Context, url string, title sql.NullString) error | |
| 26 | 26 | UpdateHistoryFavicon(ctx context.Context, faviconUrl sql.NullString, url string) error | |
| 27 | 27 | DeleteHistory(ctx context.Context, id int64) error | |
| 28 | + | DeleteAllHistory(ctx context.Context) error | |
| 28 | 29 | } | |
| 29 | 30 | ||
| 30 | 31 | // CertificateQuerier defines the interface for certificate validation-related database operations | |
| @@ -25,6 +25,7 @@ type HistoryQuerier interface { | |||||
| 25 | AddOrUpdateHistory(ctx context.Context, url string, title sql.NullString) error | 25 | AddOrUpdateHistory(ctx context.Context, url string, title sql.NullString) error | ||
| 26 | UpdateHistoryFavicon(ctx context.Context, faviconUrl sql.NullString, url string) error | 26 | UpdateHistoryFavicon(ctx context.Context, faviconUrl sql.NullString, url string) error | ||
| 27 | DeleteHistory(ctx context.Context, id int64) error | 27 | DeleteHistory(ctx context.Context, id int64) error | ||
| 28 | + | DeleteAllHistory(ctx context.Context) error | |||
| 28 | } | 29 | } | ||
| 29 | 30 | ||||
| 30 | // CertificateQuerier defines the interface for certificate validation-related database operations | 31 | // CertificateQuerier defines the interface for certificate validation-related database operations | ||
M internal/db/querier.go +1 -0
| @@ -15,6 +15,7 @@ type Querier interface { | |||
| 15 | 15 | CleanupOldZoomLevels(ctx context.Context, dollar_1 sql.NullString) error | |
| 16 | 16 | // Insert a new favorite with auto-incremented position | |
| 17 | 17 | CreateFavorite(ctx context.Context, url string, title sql.NullString, faviconUrl sql.NullString) error | |
| 18 | + | DeleteAllHistory(ctx context.Context) error | |
| 18 | 19 | DeleteCertificateValidation(ctx context.Context, hostname string, certificateHash string) error | |
| 19 | 20 | DeleteExpiredCertificateValidations(ctx context.Context) error | |
| 20 | 21 | // Delete a favorite by URL | |
| @@ -15,6 +15,7 @@ type Querier interface { | |||||
| 15 | CleanupOldZoomLevels(ctx context.Context, dollar_1 sql.NullString) error | 15 | CleanupOldZoomLevels(ctx context.Context, dollar_1 sql.NullString) error | ||
| 16 | // Insert a new favorite with auto-incremented position | 16 | // Insert a new favorite with auto-incremented position | ||
| 17 | CreateFavorite(ctx context.Context, url string, title sql.NullString, faviconUrl sql.NullString) error | 17 | CreateFavorite(ctx context.Context, url string, title sql.NullString, faviconUrl sql.NullString) error | ||
| 18 | + | DeleteAllHistory(ctx context.Context) error | |||
| 18 | DeleteCertificateValidation(ctx context.Context, hostname string, certificateHash string) error | 19 | DeleteCertificateValidation(ctx context.Context, hostname string, certificateHash string) error | ||
| 19 | DeleteExpiredCertificateValidations(ctx context.Context) error | 20 | DeleteExpiredCertificateValidations(ctx context.Context) error | ||
| 20 | // Delete a favorite by URL | 21 | // Delete a favorite by URL | ||
M internal/db/queries/history.sql +3 -0
| @@ -41,6 +41,9 @@ LIMIT 1; | |||
| 41 | 41 | DELETE FROM history | |
| 42 | 42 | WHERE id = ?; | |
| 43 | 43 | ||
| 44 | + | -- name: DeleteAllHistory :exec | |
| 45 | + | DELETE FROM history; | |
| 46 | + | ||
| 44 | 47 | -- name: GetMostVisited :many | |
| 45 | 48 | SELECT * | |
| 46 | 49 | FROM history | |
| @@ -41,6 +41,9 @@ LIMIT 1; | |||||
| 41 | DELETE FROM history | 41 | DELETE FROM history | ||
| 42 | WHERE id = ?; | 42 | WHERE id = ?; | ||
| 43 | 43 | ||||
| 44 | + | -- name: DeleteAllHistory :exec | |||
| 45 | + | DELETE FROM history; | |||
| 46 | + | ||||
| 44 | -- name: GetMostVisited :many | 47 | -- name: GetMostVisited :many | ||
| 45 | SELECT * | 48 | SELECT * | ||
| 46 | FROM history | 49 | FROM history | ||