Go · 5053 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: workflow_step_log_chunks.sql
5
6 package actionsdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const appendStepLogChunk = `-- name: AppendStepLogChunk :one
15
16 INSERT INTO workflow_step_log_chunks (step_id, seq, chunk)
17 VALUES ($1, $2, $3)
18 ON CONFLICT (step_id, seq) DO NOTHING
19 RETURNING id, step_id, seq, created_at
20 `
21
22 type AppendStepLogChunkParams struct {
23 StepID int64
24 Seq int32
25 Chunk []byte
26 }
27
28 type AppendStepLogChunkRow struct {
29 ID int64
30 StepID int64
31 Seq int32
32 CreatedAt pgtype.Timestamptz
33 }
34
35 // SPDX-License-Identifier: AGPL-3.0-or-later
36 func (q *Queries) AppendStepLogChunk(ctx context.Context, db DBTX, arg AppendStepLogChunkParams) (AppendStepLogChunkRow, error) {
37 row := db.QueryRow(ctx, appendStepLogChunk, arg.StepID, arg.Seq, arg.Chunk)
38 var i AppendStepLogChunkRow
39 err := row.Scan(
40 &i.ID,
41 &i.StepID,
42 &i.Seq,
43 &i.CreatedAt,
44 )
45 return i, err
46 }
47
48 const deleteStaleStepLogChunksForCleanup = `-- name: DeleteStaleStepLogChunksForCleanup :execrows
49 DELETE FROM workflow_step_log_chunks c
50 USING workflow_steps s
51 WHERE c.step_id = s.id
52 AND s.status IN ('completed', 'cancelled', 'skipped')
53 AND s.completed_at IS NOT NULL
54 AND s.completed_at < $1
55 `
56
57 func (q *Queries) DeleteStaleStepLogChunksForCleanup(ctx context.Context, db DBTX, completedAt pgtype.Timestamptz) (int64, error) {
58 result, err := db.Exec(ctx, deleteStaleStepLogChunksForCleanup, completedAt)
59 if err != nil {
60 return 0, err
61 }
62 return result.RowsAffected(), nil
63 }
64
65 const deleteStepLogChunks = `-- name: DeleteStepLogChunks :exec
66 DELETE FROM workflow_step_log_chunks WHERE step_id = $1
67 `
68
69 func (q *Queries) DeleteStepLogChunks(ctx context.Context, db DBTX, stepID int64) error {
70 _, err := db.Exec(ctx, deleteStepLogChunks, stepID)
71 return err
72 }
73
74 const getStepLogChunkBefore = `-- name: GetStepLogChunkBefore :one
75 SELECT id, step_id, seq, chunk, created_at
76 FROM workflow_step_log_chunks
77 WHERE step_id = $1 AND seq < $2
78 ORDER BY seq DESC
79 LIMIT 1
80 `
81
82 type GetStepLogChunkBeforeParams struct {
83 StepID int64
84 Seq int32
85 }
86
87 func (q *Queries) GetStepLogChunkBefore(ctx context.Context, db DBTX, arg GetStepLogChunkBeforeParams) (WorkflowStepLogChunk, error) {
88 row := db.QueryRow(ctx, getStepLogChunkBefore, arg.StepID, arg.Seq)
89 var i WorkflowStepLogChunk
90 err := row.Scan(
91 &i.ID,
92 &i.StepID,
93 &i.Seq,
94 &i.Chunk,
95 &i.CreatedAt,
96 )
97 return i, err
98 }
99
100 const getStepLogChunkByStepSeq = `-- name: GetStepLogChunkByStepSeq :one
101 SELECT id, step_id, seq, chunk, created_at
102 FROM workflow_step_log_chunks
103 WHERE step_id = $1 AND seq = $2
104 `
105
106 type GetStepLogChunkByStepSeqParams struct {
107 StepID int64
108 Seq int32
109 }
110
111 func (q *Queries) GetStepLogChunkByStepSeq(ctx context.Context, db DBTX, arg GetStepLogChunkByStepSeqParams) (WorkflowStepLogChunk, error) {
112 row := db.QueryRow(ctx, getStepLogChunkByStepSeq, arg.StepID, arg.Seq)
113 var i WorkflowStepLogChunk
114 err := row.Scan(
115 &i.ID,
116 &i.StepID,
117 &i.Seq,
118 &i.Chunk,
119 &i.CreatedAt,
120 )
121 return i, err
122 }
123
124 const listAllStepLogChunksForStep = `-- name: ListAllStepLogChunksForStep :many
125 SELECT id, step_id, seq, chunk, created_at
126 FROM workflow_step_log_chunks
127 WHERE step_id = $1
128 ORDER BY seq ASC
129 `
130
131 func (q *Queries) ListAllStepLogChunksForStep(ctx context.Context, db DBTX, stepID int64) ([]WorkflowStepLogChunk, error) {
132 rows, err := db.Query(ctx, listAllStepLogChunksForStep, stepID)
133 if err != nil {
134 return nil, err
135 }
136 defer rows.Close()
137 items := []WorkflowStepLogChunk{}
138 for rows.Next() {
139 var i WorkflowStepLogChunk
140 if err := rows.Scan(
141 &i.ID,
142 &i.StepID,
143 &i.Seq,
144 &i.Chunk,
145 &i.CreatedAt,
146 ); err != nil {
147 return nil, err
148 }
149 items = append(items, i)
150 }
151 if err := rows.Err(); err != nil {
152 return nil, err
153 }
154 return items, nil
155 }
156
157 const listStepLogChunks = `-- name: ListStepLogChunks :many
158 SELECT id, step_id, seq, chunk, created_at
159 FROM workflow_step_log_chunks
160 WHERE step_id = $1 AND seq > $2
161 ORDER BY seq ASC
162 LIMIT $3
163 `
164
165 type ListStepLogChunksParams struct {
166 StepID int64
167 Seq int32
168 Limit int32
169 }
170
171 func (q *Queries) ListStepLogChunks(ctx context.Context, db DBTX, arg ListStepLogChunksParams) ([]WorkflowStepLogChunk, error) {
172 rows, err := db.Query(ctx, listStepLogChunks, arg.StepID, arg.Seq, arg.Limit)
173 if err != nil {
174 return nil, err
175 }
176 defer rows.Close()
177 items := []WorkflowStepLogChunk{}
178 for rows.Next() {
179 var i WorkflowStepLogChunk
180 if err := rows.Scan(
181 &i.ID,
182 &i.StepID,
183 &i.Seq,
184 &i.Chunk,
185 &i.CreatedAt,
186 ); err != nil {
187 return nil, err
188 }
189 items = append(items, i)
190 }
191 if err := rows.Err(); err != nil {
192 return nil, err
193 }
194 return items, nil
195 }
196
197 const updateStepLogChunk = `-- name: UpdateStepLogChunk :exec
198 UPDATE workflow_step_log_chunks
199 SET chunk = $2
200 WHERE id = $1
201 `
202
203 type UpdateStepLogChunkParams struct {
204 ID int64
205 Chunk []byte
206 }
207
208 func (q *Queries) UpdateStepLogChunk(ctx context.Context, db DBTX, arg UpdateStepLogChunkParams) error {
209 _, err := db.Exec(ctx, updateStepLogChunk, arg.ID, arg.Chunk)
210 return err
211 }
212