Go · 2157 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: push_events.sql
5
6 package workerdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const getPushEvent = `-- name: GetPushEvent :one
15 SELECT id, repo_id, pusher_user_id, before_sha, after_sha, ref, protocol, request_id, processed_at, created_at FROM push_events WHERE id = $1
16 `
17
18 func (q *Queries) GetPushEvent(ctx context.Context, db DBTX, id int64) (PushEvent, error) {
19 row := db.QueryRow(ctx, getPushEvent, id)
20 var i PushEvent
21 err := row.Scan(
22 &i.ID,
23 &i.RepoID,
24 &i.PusherUserID,
25 &i.BeforeSha,
26 &i.AfterSha,
27 &i.Ref,
28 &i.Protocol,
29 &i.RequestID,
30 &i.ProcessedAt,
31 &i.CreatedAt,
32 )
33 return i, err
34 }
35
36 const insertPushEvent = `-- name: InsertPushEvent :one
37
38 INSERT INTO push_events (
39 repo_id, pusher_user_id, before_sha, after_sha, ref, protocol, request_id
40 ) VALUES (
41 $1, $6::bigint, $2, $3, $4, $5, COALESCE($7::text, '')
42 )
43 RETURNING id, repo_id, pusher_user_id, before_sha, after_sha, ref, protocol, request_id, processed_at, created_at
44 `
45
46 type InsertPushEventParams struct {
47 RepoID int64
48 BeforeSha string
49 AfterSha string
50 Ref string
51 Protocol string
52 PusherUserID pgtype.Int8
53 RequestID pgtype.Text
54 }
55
56 // SPDX-License-Identifier: AGPL-3.0-or-later
57 //
58 // push_events records what landed; the post-receive hook writes; the
59 // push:process job consumes.
60 func (q *Queries) InsertPushEvent(ctx context.Context, db DBTX, arg InsertPushEventParams) (PushEvent, error) {
61 row := db.QueryRow(ctx, insertPushEvent,
62 arg.RepoID,
63 arg.BeforeSha,
64 arg.AfterSha,
65 arg.Ref,
66 arg.Protocol,
67 arg.PusherUserID,
68 arg.RequestID,
69 )
70 var i PushEvent
71 err := row.Scan(
72 &i.ID,
73 &i.RepoID,
74 &i.PusherUserID,
75 &i.BeforeSha,
76 &i.AfterSha,
77 &i.Ref,
78 &i.Protocol,
79 &i.RequestID,
80 &i.ProcessedAt,
81 &i.CreatedAt,
82 )
83 return i, err
84 }
85
86 const markPushEventProcessed = `-- name: MarkPushEventProcessed :exec
87 UPDATE push_events
88 SET processed_at = now()
89 WHERE id = $1
90 `
91
92 func (q *Queries) MarkPushEventProcessed(ctx context.Context, db DBTX, id int64) error {
93 _, err := db.Exec(ctx, markPushEventProcessed, id)
94 return err
95 }
96