207 lines
5.9 KiB
Go
207 lines
5.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: project_repositories.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const deleteUnlinkedCandidateProjectRepositories = `-- name: DeleteUnlinkedCandidateProjectRepositories :exec
|
|
DELETE FROM candidate_project_repositories
|
|
WHERE
|
|
candidate_id = $1
|
|
AND NOT (repository_key = ANY($2::text []))
|
|
`
|
|
|
|
type DeleteUnlinkedCandidateProjectRepositoriesParams struct {
|
|
CandidateID pgtype.UUID
|
|
LinkedKeys []string
|
|
}
|
|
|
|
// Removes the checks of repositories that no project links any more.
|
|
func (q *Queries) DeleteUnlinkedCandidateProjectRepositories(ctx context.Context, arg DeleteUnlinkedCandidateProjectRepositoriesParams) error {
|
|
_, err := q.db.Exec(ctx, deleteUnlinkedCandidateProjectRepositories, arg.CandidateID, arg.LinkedKeys)
|
|
return err
|
|
}
|
|
|
|
const getCandidateProjectRepositoryForUpdate = `-- name: GetCandidateProjectRepositoryForUpdate :one
|
|
SELECT
|
|
candidate_id, repository_key, state, github_id, description, topics,
|
|
languages, readme_excerpt, repository_etag, readme_etag, failure_class,
|
|
checked_at, requested_at, created_at, updated_at
|
|
FROM candidate_project_repositories
|
|
WHERE candidate_id = $1 AND repository_key = $2
|
|
FOR UPDATE
|
|
`
|
|
|
|
type GetCandidateProjectRepositoryForUpdateParams struct {
|
|
CandidateID pgtype.UUID
|
|
RepositoryKey string
|
|
}
|
|
|
|
func (q *Queries) GetCandidateProjectRepositoryForUpdate(ctx context.Context, arg GetCandidateProjectRepositoryForUpdateParams) (CandidateProjectRepository, error) {
|
|
row := q.db.QueryRow(ctx, getCandidateProjectRepositoryForUpdate, arg.CandidateID, arg.RepositoryKey)
|
|
var i CandidateProjectRepository
|
|
err := row.Scan(
|
|
&i.CandidateID,
|
|
&i.RepositoryKey,
|
|
&i.State,
|
|
&i.GithubID,
|
|
&i.Description,
|
|
&i.Topics,
|
|
&i.Languages,
|
|
&i.ReadmeExcerpt,
|
|
&i.RepositoryEtag,
|
|
&i.ReadmeEtag,
|
|
&i.FailureClass,
|
|
&i.CheckedAt,
|
|
&i.RequestedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getLatestRepositoryCheckRequest = `-- name: GetLatestRepositoryCheckRequest :one
|
|
SELECT MAX(requested_at)::timestamptz AS requested_at
|
|
FROM candidate_project_repositories
|
|
WHERE candidate_id = $1
|
|
`
|
|
|
|
// The latest check request of a candidate, for the per-candidate limit.
|
|
func (q *Queries) GetLatestRepositoryCheckRequest(ctx context.Context, candidateID pgtype.UUID) (pgtype.Timestamptz, error) {
|
|
row := q.db.QueryRow(ctx, getLatestRepositoryCheckRequest, candidateID)
|
|
var requested_at pgtype.Timestamptz
|
|
err := row.Scan(&requested_at)
|
|
return requested_at, err
|
|
}
|
|
|
|
const listCandidateProjectRepositories = `-- name: ListCandidateProjectRepositories :many
|
|
|
|
SELECT
|
|
candidate_id, repository_key, state, github_id, description, topics,
|
|
languages, readme_excerpt, repository_etag, readme_etag, failure_class,
|
|
checked_at, requested_at, created_at, updated_at
|
|
FROM candidate_project_repositories
|
|
WHERE candidate_id = $1
|
|
ORDER BY repository_key
|
|
`
|
|
|
|
// Server checks of the GitHub repositories that candidate projects link.
|
|
// Every statement is scoped by the candidate.
|
|
func (q *Queries) ListCandidateProjectRepositories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateProjectRepository, error) {
|
|
rows, err := q.db.Query(ctx, listCandidateProjectRepositories, candidateID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CandidateProjectRepository
|
|
for rows.Next() {
|
|
var i CandidateProjectRepository
|
|
if err := rows.Scan(
|
|
&i.CandidateID,
|
|
&i.RepositoryKey,
|
|
&i.State,
|
|
&i.GithubID,
|
|
&i.Description,
|
|
&i.Topics,
|
|
&i.Languages,
|
|
&i.ReadmeExcerpt,
|
|
&i.RepositoryEtag,
|
|
&i.ReadmeEtag,
|
|
&i.FailureClass,
|
|
&i.CheckedAt,
|
|
&i.RequestedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const requestCandidateProjectRepositoryCheck = `-- name: RequestCandidateProjectRepositoryCheck :exec
|
|
INSERT INTO candidate_project_repositories (
|
|
candidate_id, repository_key, state, requested_at, created_at, updated_at
|
|
) VALUES (
|
|
$1, $2, 'pending', $3,
|
|
$3, $3
|
|
)
|
|
ON CONFLICT (candidate_id, repository_key) DO UPDATE
|
|
SET
|
|
requested_at = excluded.requested_at,
|
|
updated_at = GREATEST(candidate_project_repositories.updated_at, excluded.updated_at)
|
|
`
|
|
|
|
type RequestCandidateProjectRepositoryCheckParams struct {
|
|
CandidateID pgtype.UUID
|
|
RepositoryKey string
|
|
RequestedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// A new repository starts pending; a known one only records the request.
|
|
func (q *Queries) RequestCandidateProjectRepositoryCheck(ctx context.Context, arg RequestCandidateProjectRepositoryCheckParams) error {
|
|
_, err := q.db.Exec(ctx, requestCandidateProjectRepositoryCheck, arg.CandidateID, arg.RepositoryKey, arg.RequestedAt)
|
|
return err
|
|
}
|
|
|
|
const saveCandidateProjectRepositoryCheck = `-- name: SaveCandidateProjectRepositoryCheck :exec
|
|
UPDATE candidate_project_repositories
|
|
SET
|
|
state = $1,
|
|
github_id = $2,
|
|
description = $3,
|
|
topics = $4,
|
|
languages = $5,
|
|
readme_excerpt = $6,
|
|
repository_etag = $7,
|
|
readme_etag = $8,
|
|
failure_class = $9,
|
|
checked_at = $10,
|
|
updated_at = GREATEST(updated_at, $10)
|
|
WHERE candidate_id = $11 AND repository_key = $12
|
|
`
|
|
|
|
type SaveCandidateProjectRepositoryCheckParams struct {
|
|
State string
|
|
GithubID pgtype.Int8
|
|
Description pgtype.Text
|
|
Topics []string
|
|
Languages []string
|
|
ReadmeExcerpt pgtype.Text
|
|
RepositoryEtag pgtype.Text
|
|
ReadmeEtag pgtype.Text
|
|
FailureClass pgtype.Text
|
|
CheckedAt pgtype.Timestamptz
|
|
CandidateID pgtype.UUID
|
|
RepositoryKey string
|
|
}
|
|
|
|
func (q *Queries) SaveCandidateProjectRepositoryCheck(ctx context.Context, arg SaveCandidateProjectRepositoryCheckParams) error {
|
|
_, err := q.db.Exec(ctx, saveCandidateProjectRepositoryCheck,
|
|
arg.State,
|
|
arg.GithubID,
|
|
arg.Description,
|
|
arg.Topics,
|
|
arg.Languages,
|
|
arg.ReadmeExcerpt,
|
|
arg.RepositoryEtag,
|
|
arg.ReadmeEtag,
|
|
arg.FailureClass,
|
|
arg.CheckedAt,
|
|
arg.CandidateID,
|
|
arg.RepositoryKey,
|
|
)
|
|
return err
|
|
}
|