| 1 | package store |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | // SetForkOf legt vast dat repo een fork is van upstream. |
| 6 | func (s *Store) SetForkOf(ctx context.Context, repoID, upstreamID int64) error { |
| 7 | _, err := s.db.ExecContext(ctx, `UPDATE repos SET fork_of = ? WHERE id = ?`, upstreamID, repoID) |
| 8 | return err |
| 9 | } |
| 10 | |
| 11 | // ForkOf geeft de upstream-id (0 = geen fork). |
| 12 | func (s *Store) ForkOf(ctx context.Context, repoID int64) (int64, error) { |
| 13 | var id int64 |
| 14 | err := s.db.QueryRowContext(ctx, `SELECT fork_of FROM repos WHERE id = ?`, repoID).Scan(&id) |
| 15 | return id, err |
| 16 | } |
| 17 | |
| 18 | // ForkIDs geeft de ids van de directe forks van upstream. |
| 19 | func (s *Store) ForkIDs(ctx context.Context, upstreamID int64) ([]int64, error) { |
| 20 | rows, err := s.db.QueryContext(ctx, `SELECT id FROM repos WHERE fork_of = ? ORDER BY id`, upstreamID) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | defer rows.Close() |
| 25 | var out []int64 |
| 26 | for rows.Next() { |
| 27 | var id int64 |
| 28 | if err := rows.Scan(&id); err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | out = append(out, id) |
| 32 | } |
| 33 | return out, rows.Err() |
| 34 | } |