internal/store/topics.go

191da4bb528ee095de7ce47d59ee2c8e456cf483
gitbay/internal/store/topics.go

38 lines · 944 bytes

 1package store
 2
 3func (s *Store) ListTopics(repoID int64) ([]string, error) {
 4	rows, err := s.DB.Query("SELECT topic FROM repo_topics WHERE repo_id = ? ORDER BY topic", repoID)
 5	if err != nil {
 6		return nil, err
 7	}
 8	defer rows.Close()
 9	var out []string
10	for rows.Next() {
11		var t string
12		if err := rows.Scan(&t); err != nil {
13			return nil, err
14		}
15		out = append(out, t)
16	}
17	return out, rows.Err()
18}
19
20// AddTopic is idempotent: adding an existing topic is not an error.
21func (s *Store) AddTopic(repoID int64, topic string) error {
22	_, err := s.DB.Exec(
23		"INSERT INTO repo_topics (repo_id, topic) VALUES (?, ?) ON CONFLICT DO NOTHING",
24		repoID, topic)
25	return err
26}
27
28func (s *Store) RemoveTopic(repoID int64, topic string) error {
29	res, err := s.DB.Exec(
30		"DELETE FROM repo_topics WHERE repo_id = ? AND topic = ?", repoID, topic)
31	if err != nil {
32		return err
33	}
34	if n, _ := res.RowsAffected(); n == 0 {
35		return ErrNotFound
36	}
37	return nil
38}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form