| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: workflow_artifacts.sql |
| 5 | |
| 6 | package actionsdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const deleteWorkflowArtifactByID = `-- name: DeleteWorkflowArtifactByID :execrows |
| 15 | DELETE FROM workflow_artifacts WHERE id = $1 |
| 16 | ` |
| 17 | |
| 18 | func (q *Queries) DeleteWorkflowArtifactByID(ctx context.Context, db DBTX, id int64) (int64, error) { |
| 19 | result, err := db.Exec(ctx, deleteWorkflowArtifactByID, id) |
| 20 | if err != nil { |
| 21 | return 0, err |
| 22 | } |
| 23 | return result.RowsAffected(), nil |
| 24 | } |
| 25 | |
| 26 | const deleteWorkflowArtifactsByIDs = `-- name: DeleteWorkflowArtifactsByIDs :execrows |
| 27 | DELETE FROM workflow_artifacts |
| 28 | WHERE id = ANY($1::bigint[]) |
| 29 | ` |
| 30 | |
| 31 | func (q *Queries) DeleteWorkflowArtifactsByIDs(ctx context.Context, db DBTX, dollar_1 []int64) (int64, error) { |
| 32 | result, err := db.Exec(ctx, deleteWorkflowArtifactsByIDs, dollar_1) |
| 33 | if err != nil { |
| 34 | return 0, err |
| 35 | } |
| 36 | return result.RowsAffected(), nil |
| 37 | } |
| 38 | |
| 39 | const getArtifactByID = `-- name: GetArtifactByID :one |
| 40 | SELECT id, run_id, name, object_key, byte_count, expires_at, created_at |
| 41 | FROM workflow_artifacts |
| 42 | WHERE id = $1 |
| 43 | ` |
| 44 | |
| 45 | func (q *Queries) GetArtifactByID(ctx context.Context, db DBTX, id int64) (WorkflowArtifact, error) { |
| 46 | row := db.QueryRow(ctx, getArtifactByID, id) |
| 47 | var i WorkflowArtifact |
| 48 | err := row.Scan( |
| 49 | &i.ID, |
| 50 | &i.RunID, |
| 51 | &i.Name, |
| 52 | &i.ObjectKey, |
| 53 | &i.ByteCount, |
| 54 | &i.ExpiresAt, |
| 55 | &i.CreatedAt, |
| 56 | ) |
| 57 | return i, err |
| 58 | } |
| 59 | |
| 60 | const insertArtifact = `-- name: InsertArtifact :one |
| 61 | |
| 62 | INSERT INTO workflow_artifacts (run_id, name, object_key, byte_count, expires_at) |
| 63 | VALUES ($1, $2, $3, $4, $5) |
| 64 | RETURNING id, run_id, name, object_key, byte_count, expires_at, created_at |
| 65 | ` |
| 66 | |
| 67 | type InsertArtifactParams struct { |
| 68 | RunID int64 |
| 69 | Name string |
| 70 | ObjectKey string |
| 71 | ByteCount int64 |
| 72 | ExpiresAt pgtype.Timestamptz |
| 73 | } |
| 74 | |
| 75 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 76 | func (q *Queries) InsertArtifact(ctx context.Context, db DBTX, arg InsertArtifactParams) (WorkflowArtifact, error) { |
| 77 | row := db.QueryRow(ctx, insertArtifact, |
| 78 | arg.RunID, |
| 79 | arg.Name, |
| 80 | arg.ObjectKey, |
| 81 | arg.ByteCount, |
| 82 | arg.ExpiresAt, |
| 83 | ) |
| 84 | var i WorkflowArtifact |
| 85 | err := row.Scan( |
| 86 | &i.ID, |
| 87 | &i.RunID, |
| 88 | &i.Name, |
| 89 | &i.ObjectKey, |
| 90 | &i.ByteCount, |
| 91 | &i.ExpiresAt, |
| 92 | &i.CreatedAt, |
| 93 | ) |
| 94 | return i, err |
| 95 | } |
| 96 | |
| 97 | const listArtifactObjectKeysForRun = `-- name: ListArtifactObjectKeysForRun :many |
| 98 | SELECT object_key |
| 99 | FROM workflow_artifacts |
| 100 | WHERE run_id = $1 |
| 101 | ` |
| 102 | |
| 103 | // Used by the run-delete REST handler to drive a best-effort S3 |
| 104 | // cleanup after the workflow_runs row (and its cascaded |
| 105 | // workflow_artifacts rows) have been removed. |
| 106 | func (q *Queries) ListArtifactObjectKeysForRun(ctx context.Context, db DBTX, runID int64) ([]string, error) { |
| 107 | rows, err := db.Query(ctx, listArtifactObjectKeysForRun, runID) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | defer rows.Close() |
| 112 | items := []string{} |
| 113 | for rows.Next() { |
| 114 | var object_key string |
| 115 | if err := rows.Scan(&object_key); err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | items = append(items, object_key) |
| 119 | } |
| 120 | if err := rows.Err(); err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | return items, nil |
| 124 | } |
| 125 | |
| 126 | const listArtifactsForRun = `-- name: ListArtifactsForRun :many |
| 127 | SELECT id, name, object_key, byte_count, expires_at, created_at |
| 128 | FROM workflow_artifacts |
| 129 | WHERE run_id = $1 |
| 130 | ORDER BY name ASC |
| 131 | ` |
| 132 | |
| 133 | type ListArtifactsForRunRow struct { |
| 134 | ID int64 |
| 135 | Name string |
| 136 | ObjectKey string |
| 137 | ByteCount int64 |
| 138 | ExpiresAt pgtype.Timestamptz |
| 139 | CreatedAt pgtype.Timestamptz |
| 140 | } |
| 141 | |
| 142 | func (q *Queries) ListArtifactsForRun(ctx context.Context, db DBTX, runID int64) ([]ListArtifactsForRunRow, error) { |
| 143 | rows, err := db.Query(ctx, listArtifactsForRun, runID) |
| 144 | if err != nil { |
| 145 | return nil, err |
| 146 | } |
| 147 | defer rows.Close() |
| 148 | items := []ListArtifactsForRunRow{} |
| 149 | for rows.Next() { |
| 150 | var i ListArtifactsForRunRow |
| 151 | if err := rows.Scan( |
| 152 | &i.ID, |
| 153 | &i.Name, |
| 154 | &i.ObjectKey, |
| 155 | &i.ByteCount, |
| 156 | &i.ExpiresAt, |
| 157 | &i.CreatedAt, |
| 158 | ); err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | items = append(items, i) |
| 162 | } |
| 163 | if err := rows.Err(); err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | return items, nil |
| 167 | } |
| 168 | |
| 169 | const listExpiredWorkflowArtifactsForCleanup = `-- name: ListExpiredWorkflowArtifactsForCleanup :many |
| 170 | SELECT id, object_key |
| 171 | FROM workflow_artifacts |
| 172 | WHERE expires_at < $1 |
| 173 | AND object_key LIKE 'actions/runs/%' |
| 174 | ORDER BY expires_at ASC, id ASC |
| 175 | LIMIT $2 |
| 176 | ` |
| 177 | |
| 178 | type ListExpiredWorkflowArtifactsForCleanupParams struct { |
| 179 | ExpiresAt pgtype.Timestamptz |
| 180 | Limit int32 |
| 181 | } |
| 182 | |
| 183 | type ListExpiredWorkflowArtifactsForCleanupRow struct { |
| 184 | ID int64 |
| 185 | ObjectKey string |
| 186 | } |
| 187 | |
| 188 | func (q *Queries) ListExpiredWorkflowArtifactsForCleanup(ctx context.Context, db DBTX, arg ListExpiredWorkflowArtifactsForCleanupParams) ([]ListExpiredWorkflowArtifactsForCleanupRow, error) { |
| 189 | rows, err := db.Query(ctx, listExpiredWorkflowArtifactsForCleanup, arg.ExpiresAt, arg.Limit) |
| 190 | if err != nil { |
| 191 | return nil, err |
| 192 | } |
| 193 | defer rows.Close() |
| 194 | items := []ListExpiredWorkflowArtifactsForCleanupRow{} |
| 195 | for rows.Next() { |
| 196 | var i ListExpiredWorkflowArtifactsForCleanupRow |
| 197 | if err := rows.Scan(&i.ID, &i.ObjectKey); err != nil { |
| 198 | return nil, err |
| 199 | } |
| 200 | items = append(items, i) |
| 201 | } |
| 202 | if err := rows.Err(); err != nil { |
| 203 | return nil, err |
| 204 | } |
| 205 | return items, nil |
| 206 | } |
| 207 |