smutok/internal/store/sqlite_feeds.go(view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
package store
import (
"context"
"fmt"
"strings"
)
func (s *Sqlite) UpsertSubscription(ctx context.Context, id, title, url, htmlURL string) error {
_, err := s.db.ExecContext(ctx,
`insert or ignore into feeds (id, title, url, htmlUrl)
values (?, ?, ?, ?)`,
id, title, url, htmlURL)
return err
}
func (s *Sqlite) LinkFeedWithFolder(ctx context.Context, feedID, folderID string) error {
_, err := s.db.ExecContext(ctx,
`insert or ignore into feed_folders (feed_id, folder_id)
values (?, ?)`,
feedID, folderID)
return err
}
func (s *Sqlite) RemoveNonExistentFeeds(ctx context.Context, currentFeedIDs []string) error {
if len(currentFeedIDs) == 0 {
_, err := s.db.ExecContext(ctx, "delete from feeds")
return err
}
values := strings.Repeat("(?),", len(currentFeedIDs))
values = values[:len(values)-1] // trim trailing comma
query := fmt.Sprintf(`--sql
DELETE FROM feeds
WHERE id NOT IN (VALUES %s)
`, values)
args := make([]any, len(currentFeedIDs))
for i, v := range currentFeedIDs {
args[i] = v
}
_, err := s.db.ExecContext(ctx, query, args...)
return err
}
|