// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: workflow_caches.sql package actionsdb import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const countWorkflowCachesForRepo = `-- name: CountWorkflowCachesForRepo :one SELECT COUNT(*) FROM workflow_caches WHERE repo_id = $1 AND ($2::text IS NULL OR git_ref = $2::text) AND ($3::text IS NULL OR cache_key = $3::text) ` type CountWorkflowCachesForRepoParams struct { RepoID int64 GitRef pgtype.Text CacheKey pgtype.Text } func (q *Queries) CountWorkflowCachesForRepo(ctx context.Context, db DBTX, arg CountWorkflowCachesForRepoParams) (int64, error) { row := db.QueryRow(ctx, countWorkflowCachesForRepo, arg.RepoID, arg.GitRef, arg.CacheKey) var count int64 err := row.Scan(&count) return count, err } const deleteWorkflowCacheByID = `-- name: DeleteWorkflowCacheByID :execrows DELETE FROM workflow_caches WHERE id = $1 AND repo_id = $2 ` type DeleteWorkflowCacheByIDParams struct { ID int64 RepoID int64 } func (q *Queries) DeleteWorkflowCacheByID(ctx context.Context, db DBTX, arg DeleteWorkflowCacheByIDParams) (int64, error) { result, err := db.Exec(ctx, deleteWorkflowCacheByID, arg.ID, arg.RepoID) if err != nil { return 0, err } return result.RowsAffected(), nil } const deleteWorkflowCachesByKey = `-- name: DeleteWorkflowCachesByKey :many WITH deleted AS ( DELETE FROM workflow_caches WHERE repo_id = $1 AND cache_key = $2 AND ($3::text IS NULL OR git_ref = $3::text) RETURNING object_key ) SELECT object_key FROM deleted ` type DeleteWorkflowCachesByKeyParams struct { RepoID int64 CacheKey string GitRef pgtype.Text } // Returns the deleted rows' object_keys so the handler can purge the // backing tarballs from object storage. func (q *Queries) DeleteWorkflowCachesByKey(ctx context.Context, db DBTX, arg DeleteWorkflowCachesByKeyParams) ([]string, error) { rows, err := db.Query(ctx, deleteWorkflowCachesByKey, arg.RepoID, arg.CacheKey, arg.GitRef) if err != nil { return nil, err } defer rows.Close() items := []string{} for rows.Next() { var object_key string if err := rows.Scan(&object_key); err != nil { return nil, err } items = append(items, object_key) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getWorkflowCacheByID = `-- name: GetWorkflowCacheByID :one SELECT id, repo_id, cache_key, cache_version, git_ref, object_key, size_bytes, last_accessed_at, created_at FROM workflow_caches WHERE id = $1 ` func (q *Queries) GetWorkflowCacheByID(ctx context.Context, db DBTX, id int64) (WorkflowCache, error) { row := db.QueryRow(ctx, getWorkflowCacheByID, id) var i WorkflowCache err := row.Scan( &i.ID, &i.RepoID, &i.CacheKey, &i.CacheVersion, &i.GitRef, &i.ObjectKey, &i.SizeBytes, &i.LastAccessedAt, &i.CreatedAt, ) return i, err } const insertWorkflowCache = `-- name: InsertWorkflowCache :one INSERT INTO workflow_caches ( repo_id, cache_key, cache_version, git_ref, object_key, size_bytes ) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (repo_id, cache_key, cache_version, git_ref) DO UPDATE SET object_key = EXCLUDED.object_key, size_bytes = EXCLUDED.size_bytes, last_accessed_at = now() RETURNING id, repo_id, cache_key, cache_version, git_ref, object_key, size_bytes, last_accessed_at, created_at ` type InsertWorkflowCacheParams struct { RepoID int64 CacheKey string CacheVersion string GitRef string ObjectKey string SizeBytes int64 } // SPDX-License-Identifier: AGPL-3.0-or-later // Called by the future runner-side upload handler when an // actions/cache step completes its tarball upload. Idempotent on // (repo_id, cache_key, cache_version, git_ref): a re-upload with the // same coordinates updates size + last_accessed_at + object_key. func (q *Queries) InsertWorkflowCache(ctx context.Context, db DBTX, arg InsertWorkflowCacheParams) (WorkflowCache, error) { row := db.QueryRow(ctx, insertWorkflowCache, arg.RepoID, arg.CacheKey, arg.CacheVersion, arg.GitRef, arg.ObjectKey, arg.SizeBytes, ) var i WorkflowCache err := row.Scan( &i.ID, &i.RepoID, &i.CacheKey, &i.CacheVersion, &i.GitRef, &i.ObjectKey, &i.SizeBytes, &i.LastAccessedAt, &i.CreatedAt, ) return i, err } const listWorkflowCachesForRepo = `-- name: ListWorkflowCachesForRepo :many SELECT id, repo_id, cache_key, cache_version, git_ref, object_key, size_bytes, last_accessed_at, created_at FROM workflow_caches WHERE repo_id = $1 AND ($4::text IS NULL OR git_ref = $4::text) AND ($5::text IS NULL OR cache_key = $5::text) ORDER BY last_accessed_at DESC, id DESC LIMIT $2 OFFSET $3 ` type ListWorkflowCachesForRepoParams struct { RepoID int64 Limit int32 Offset int32 GitRef pgtype.Text CacheKey pgtype.Text } // Paginated list filtered optionally by ref + key. NULL params skip // the filter. Sorted by last_accessed_at DESC so an operator sees the // live caches first. func (q *Queries) ListWorkflowCachesForRepo(ctx context.Context, db DBTX, arg ListWorkflowCachesForRepoParams) ([]WorkflowCache, error) { rows, err := db.Query(ctx, listWorkflowCachesForRepo, arg.RepoID, arg.Limit, arg.Offset, arg.GitRef, arg.CacheKey, ) if err != nil { return nil, err } defer rows.Close() items := []WorkflowCache{} for rows.Next() { var i WorkflowCache if err := rows.Scan( &i.ID, &i.RepoID, &i.CacheKey, &i.CacheVersion, &i.GitRef, &i.ObjectKey, &i.SizeBytes, &i.LastAccessedAt, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const touchWorkflowCache = `-- name: TouchWorkflowCache :exec UPDATE workflow_caches SET last_accessed_at = now() WHERE id = $1 ` // Bumps last_accessed_at on cache hit. Called by the future // restore-side handler. func (q *Queries) TouchWorkflowCache(ctx context.Context, db DBTX, id int64) error { _, err := db.Exec(ctx, touchWorkflowCache, id) return err }