feat(db): add GetHistoryEntry query for favicon lookup
- commit
- 1534d2b95b11280625b6fb04f431f0f983719559
- author
- bamen · · 2025-10-06 16:32 UTC
- committer
- bamen · · 2025-10-06 18:28 UTC
- parent
- 8c77b69
- signature
- unsigned
3 files · +31 -2
M internal/db/history.sql.go +23 -1
| @@ -73,6 +73,28 @@ func (q *Queries) GetHistory(ctx context.Context, limit int64) ([]History, error | |||
| 73 | 73 | return items, nil | |
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | + | const GetHistoryEntry = `-- name: GetHistoryEntry :one | |
| 77 | + | SELECT id, url, title, visit_count, last_visited, created_at, favicon_url | |
| 78 | + | FROM history | |
| 79 | + | WHERE url = ? | |
| 80 | + | LIMIT 1 | |
| 81 | + | ` | |
| 82 | + | ||
| 83 | + | func (q *Queries) GetHistoryEntry(ctx context.Context, url string) (History, error) { | |
| 84 | + | row := q.db.QueryRowContext(ctx, GetHistoryEntry, url) | |
| 85 | + | var i History | |
| 86 | + | err := row.Scan( | |
| 87 | + | &i.ID, | |
| 88 | + | &i.Url, | |
| 89 | + | &i.Title, | |
| 90 | + | &i.VisitCount, | |
| 91 | + | &i.LastVisited, | |
| 92 | + | &i.CreatedAt, | |
| 93 | + | &i.FaviconUrl, | |
| 94 | + | ) | |
| 95 | + | return i, err | |
| 96 | + | } | |
| 97 | + | ||
| 76 | 98 | const GetHistoryWithOffset = `-- name: GetHistoryWithOffset :many | |
| 77 | 99 | SELECT id, url, title, visit_count, last_visited, created_at, favicon_url | |
| 78 | 100 | FROM history | |
| @@ -186,7 +208,7 @@ func (q *Queries) SearchHistory(ctx context.Context, column1 sql.NullString, col | |||
| 186 | 208 | } | |
| 187 | 209 | ||
| 188 | 210 | const UpdateHistoryFavicon = `-- name: UpdateHistoryFavicon :exec | |
| 189 | - | UPDATE history | |
| 211 | + | UPDATE history | |
| 190 | 212 | SET favicon_url = ? | |
| 191 | 213 | WHERE url = ? | |
| 192 | 214 | ` | |
| @@ -73,6 +73,28 @@ func (q *Queries) GetHistory(ctx context.Context, limit int64) ([]History, error | |||||
| 73 | return items, nil | 73 | return items, nil | ||
| 74 | } | 74 | } | ||
| 75 | 75 | ||||
| 76 | + | const GetHistoryEntry = `-- name: GetHistoryEntry :one | |||
| 77 | + | SELECT id, url, title, visit_count, last_visited, created_at, favicon_url | |||
| 78 | + | FROM history | |||
| 79 | + | WHERE url = ? | |||
| 80 | + | LIMIT 1 | |||
| 81 | + | ` | |||
| 82 | + | ||||
| 83 | + | func (q *Queries) GetHistoryEntry(ctx context.Context, url string) (History, error) { | |||
| 84 | + | row := q.db.QueryRowContext(ctx, GetHistoryEntry, url) | |||
| 85 | + | var i History | |||
| 86 | + | err := row.Scan( | |||
| 87 | + | &i.ID, | |||
| 88 | + | &i.Url, | |||
| 89 | + | &i.Title, | |||
| 90 | + | &i.VisitCount, | |||
| 91 | + | &i.LastVisited, | |||
| 92 | + | &i.CreatedAt, | |||
| 93 | + | &i.FaviconUrl, | |||
| 94 | + | ) | |||
| 95 | + | return i, err | |||
| 96 | + | } | |||
| 97 | + | ||||
| 76 | const GetHistoryWithOffset = `-- name: GetHistoryWithOffset :many | 98 | const GetHistoryWithOffset = `-- name: GetHistoryWithOffset :many | ||
| 77 | SELECT id, url, title, visit_count, last_visited, created_at, favicon_url | 99 | SELECT id, url, title, visit_count, last_visited, created_at, favicon_url | ||
| 78 | FROM history | 100 | FROM history | ||
| @@ -186,7 +208,7 @@ func (q *Queries) SearchHistory(ctx context.Context, column1 sql.NullString, col | |||||
| 186 | } | 208 | } | ||
| 187 | 209 | ||||
| 188 | const UpdateHistoryFavicon = `-- name: UpdateHistoryFavicon :exec | 210 | const UpdateHistoryFavicon = `-- name: UpdateHistoryFavicon :exec | ||
| 189 | - | UPDATE history | 211 | + | UPDATE history |
| 190 | SET favicon_url = ? | 212 | SET favicon_url = ? | ||
| 191 | WHERE url = ? | 213 | WHERE url = ? | ||
| 192 | ` | 214 | ` | ||
M internal/db/querier.go +1 -0
| @@ -20,6 +20,7 @@ type Querier interface { | |||
| 20 | 20 | DeleteZoomLevel(ctx context.Context, domain string) error | |
| 21 | 21 | GetCertificateValidation(ctx context.Context, hostname string, certificateHash string) (CertificateValidation, error) | |
| 22 | 22 | GetHistory(ctx context.Context, limit int64) ([]History, error) | |
| 23 | + | GetHistoryEntry(ctx context.Context, url string) (History, error) | |
| 23 | 24 | GetHistoryWithOffset(ctx context.Context, limit int64, offset int64) ([]History, error) | |
| 24 | 25 | GetShortcuts(ctx context.Context) ([]Shortcut, error) | |
| 25 | 26 | // Get zoom level for a specific domain | |
| @@ -20,6 +20,7 @@ type Querier interface { | |||||
| 20 | DeleteZoomLevel(ctx context.Context, domain string) error | 20 | DeleteZoomLevel(ctx context.Context, domain string) error | ||
| 21 | GetCertificateValidation(ctx context.Context, hostname string, certificateHash string) (CertificateValidation, error) | 21 | GetCertificateValidation(ctx context.Context, hostname string, certificateHash string) (CertificateValidation, error) | ||
| 22 | GetHistory(ctx context.Context, limit int64) ([]History, error) | 22 | GetHistory(ctx context.Context, limit int64) ([]History, error) | ||
| 23 | + | GetHistoryEntry(ctx context.Context, url string) (History, error) | |||
| 23 | GetHistoryWithOffset(ctx context.Context, limit int64, offset int64) ([]History, error) | 24 | GetHistoryWithOffset(ctx context.Context, limit int64, offset int64) ([]History, error) | ||
| 24 | GetShortcuts(ctx context.Context) ([]Shortcut, error) | 25 | GetShortcuts(ctx context.Context) ([]Shortcut, error) | ||
| 25 | // Get zoom level for a specific domain | 26 | // Get zoom level for a specific domain | ||
M internal/db/queries/history.sql +7 -1
| @@ -27,10 +27,16 @@ ORDER BY visit_count DESC, last_visited DESC | |||
| 27 | 27 | LIMIT ?; | |
| 28 | 28 | ||
| 29 | 29 | -- name: UpdateHistoryFavicon :exec | |
| 30 | - | UPDATE history | |
| 30 | + | UPDATE history | |
| 31 | 31 | SET favicon_url = ? | |
| 32 | 32 | WHERE url = ?; | |
| 33 | 33 | ||
| 34 | + | -- name: GetHistoryEntry :one | |
| 35 | + | SELECT * | |
| 36 | + | FROM history | |
| 37 | + | WHERE url = ? | |
| 38 | + | LIMIT 1; | |
| 39 | + | ||
| 34 | 40 | -- name: DeleteHistory :exec | |
| 35 | 41 | DELETE FROM history | |
| 36 | 42 | WHERE id = ?; | |
| @@ -27,10 +27,16 @@ ORDER BY visit_count DESC, last_visited DESC | |||||
| 27 | LIMIT ?; | 27 | LIMIT ?; | ||
| 28 | 28 | ||||
| 29 | -- name: UpdateHistoryFavicon :exec | 29 | -- name: UpdateHistoryFavicon :exec | ||
| 30 | - | UPDATE history | 30 | + | UPDATE history |
| 31 | SET favicon_url = ? | 31 | SET favicon_url = ? | ||
| 32 | WHERE url = ?; | 32 | WHERE url = ?; | ||
| 33 | 33 | ||||
| 34 | + | -- name: GetHistoryEntry :one | |||
| 35 | + | SELECT * | |||
| 36 | + | FROM history | |||
| 37 | + | WHERE url = ? | |||
| 38 | + | LIMIT 1; | |||
| 39 | + | ||||
| 34 | -- name: DeleteHistory :exec | 40 | -- name: DeleteHistory :exec | ||
| 35 | DELETE FROM history | 41 | DELETE FROM history | ||
| 36 | WHERE id = ?; | 42 | WHERE id = ?; | ||