-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathartifacts.sql.go
More file actions
75 lines (65 loc) · 1.81 KB
/
artifacts.sql.go
File metadata and controls
75 lines (65 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: artifacts.sql
package database
import (
"context"
"github.com/lib/pq"
)
const batchInsertArtifacts = `-- name: BatchInsertArtifacts :exec
INSERT INTO artifacts (reference, size_bytes)
SELECT unnest($1::TEXT[]), unnest($2::BIGINT[])
ON CONFLICT (reference) DO NOTHING
`
type BatchInsertArtifactsParams struct {
Refs []string
Sizes []int64
}
func (q *Queries) BatchInsertArtifacts(ctx context.Context, arg BatchInsertArtifactsParams) error {
_, err := q.db.ExecContext(ctx, batchInsertArtifacts, pq.Array(arg.Refs), pq.Array(arg.Sizes))
return err
}
const deleteOrphanedArtifacts = `-- name: DeleteOrphanedArtifacts :exec
DELETE FROM artifacts
WHERE id NOT IN (
SELECT unnest(artifact_ids) FROM satellite_status
WHERE artifact_ids IS NOT NULL
)
AND created_at < NOW() - INTERVAL '1 day' * $1
`
func (q *Queries) DeleteOrphanedArtifacts(ctx context.Context, retentionDays interface{}) error {
_, err := q.db.ExecContext(ctx, deleteOrphanedArtifacts, retentionDays)
return err
}
const getArtifactIDsByReferences = `-- name: GetArtifactIDsByReferences :many
SELECT id, reference, size_bytes, created_at FROM artifacts
WHERE reference = ANY($1::TEXT[])
`
func (q *Queries) GetArtifactIDsByReferences(ctx context.Context, refs []string) ([]Artifact, error) {
rows, err := q.db.QueryContext(ctx, getArtifactIDsByReferences, pq.Array(refs))
if err != nil {
return nil, err
}
defer rows.Close()
var items []Artifact
for rows.Next() {
var i Artifact
if err := rows.Scan(
&i.ID,
&i.Reference,
&i.SizeBytes,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}