Files
mtusi2026lab5/internal/database/sqlc/versioned_pipeline.sql.go
T

112 lines
3.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: versioned_pipeline.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getPipelineJobID = `-- name: GetPipelineJobID :one
SELECT id FROM attachment_jobs
WHERE attachment_id = $1::uuid AND pipeline_version = $2::int
`
type GetPipelineJobIDParams struct {
AttachmentID pgtype.UUID
PipelineVersion int32
}
func (q *Queries) GetPipelineJobID(ctx context.Context, arg GetPipelineJobIDParams) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, getPipelineJobID, arg.AttachmentID, arg.PipelineVersion)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const getPublishedOriginalKey = `-- name: GetPublishedOriginalKey :one
SELECT published_original_key FROM attachment_jobs
WHERE attachment_id = $1::uuid AND pipeline_version = $2::int
AND published_original_key IS NOT NULL
`
type GetPublishedOriginalKeyParams struct {
AttachmentID pgtype.UUID
PipelineVersion int32
}
func (q *Queries) GetPublishedOriginalKey(ctx context.Context, arg GetPublishedOriginalKeyParams) (pgtype.Text, error) {
row := q.db.QueryRow(ctx, getPublishedOriginalKey, arg.AttachmentID, arg.PipelineVersion)
var published_original_key pgtype.Text
err := row.Scan(&published_original_key)
return published_original_key, err
}
const isPublishedOriginalKey = `-- name: IsPublishedOriginalKey :one
SELECT EXISTS (SELECT 1 FROM attachment_jobs WHERE published_original_key = $1::text)
`
func (q *Queries) IsPublishedOriginalKey(ctx context.Context, objectKey string) (bool, error) {
row := q.db.QueryRow(ctx, isPublishedOriginalKey, objectKey)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const queueAttachmentUpgrade = `-- name: QueueAttachmentUpgrade :one
UPDATE attachments
SET pipeline_version = 2, status = 'queued', staging_key = $1::text,
object_key = NULL, error_code = NULL, updated_at = clock_timestamp()
WHERE id = $2::uuid AND pipeline_version = 1
RETURNING id, chat_id, owner_id, filename, object_key, content_type, size_bytes, sha256, created_at, updated_at, status, error_code, staging_key, pipeline_version
`
type QueueAttachmentUpgradeParams struct {
SourceKey string
ID pgtype.UUID
}
func (q *Queries) QueueAttachmentUpgrade(ctx context.Context, arg QueueAttachmentUpgradeParams) (Attachment, error) {
row := q.db.QueryRow(ctx, queueAttachmentUpgrade, arg.SourceKey, arg.ID)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.Filename,
&i.ObjectKey,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.CreatedAt,
&i.UpdatedAt,
&i.Status,
&i.ErrorCode,
&i.StagingKey,
&i.PipelineVersion,
)
return i, err
}
const supersedeAttachmentJob = `-- name: SupersedeAttachmentJob :exec
WITH superseded AS (
UPDATE attachment_jobs
SET lease_until = NULL, next_attempt_at = NULL, updated_at = clock_timestamp()
WHERE id = $1::uuid
RETURNING id, updated_at
)
UPDATE attachment_attempts AS attempt
SET outcome = 'superseded', error_code = 'superseded', finished_at = superseded.updated_at
FROM superseded
WHERE attempt.job_id = superseded.id AND attempt.finished_at IS NULL
`
func (q *Queries) SupersedeAttachmentJob(ctx context.Context, jobID pgtype.UUID) error {
_, err := q.db.Exec(ctx, supersedeAttachmentJob, jobID)
return err
}