// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: query.sql package sqlc import ( "context" "time" ) const attachmentForDownload = `-- name: AttachmentForDownload :one SELECT a.id, a.feedback_id, a.object_key, a.mime_type, a.byte_size, a.width, a.height, a.sha256, a.state, a.created_at FROM feedback_attachments AS a JOIN feedbacks AS f ON f.id = a.feedback_id WHERE f.id = $1 AND a.id = $2 AND f.state NOT IN ('uploading', 'failed') AND a.state = 'ready' ` type AttachmentForDownloadParams struct { FeedbackID string AttachmentID string } func (q *Queries) AttachmentForDownload(ctx context.Context, arg AttachmentForDownloadParams) (FeedbackAttachment, error) { row := q.db.QueryRow(ctx, attachmentForDownload, arg.FeedbackID, arg.AttachmentID) var i FeedbackAttachment err := row.Scan( &i.ID, &i.FeedbackID, &i.ObjectKey, &i.MimeType, &i.ByteSize, &i.Width, &i.Height, &i.Sha256, &i.State, &i.CreatedAt, ) return i, err } const countFeedbacks = `-- name: CountFeedbacks :one SELECT count(*) FROM feedbacks WHERE ($1::uuid[] IS NULL OR feedbacks.user_id = ANY($1::uuid[])) AND ($2::uuid IS NULL OR feedbacks.user_id=$2::uuid) AND ($3::text = '' OR feedbacks.category = $3::text) AND ($4::text = '' OR feedbacks.state = $4::text) ` type CountFeedbacksParams struct { VisibleUsers []string UserID *string Category string State string } func (q *Queries) CountFeedbacks(ctx context.Context, arg CountFeedbacksParams) (int64, error) { row := q.db.QueryRow(ctx, countFeedbacks, arg.VisibleUsers, arg.UserID, arg.Category, arg.State, ) var count int64 err := row.Scan(&count) return count, err } const createAttachment = `-- name: CreateAttachment :exec INSERT INTO feedback_attachments ( id, feedback_id, object_key, mime_type, byte_size, width, height, sha256, state ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'pending') ` type CreateAttachmentParams struct { ID string FeedbackID string ObjectKey string MimeType string ByteSize int64 Width int32 Height int32 Sha256 string } func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) error { _, err := q.db.Exec(ctx, createAttachment, arg.ID, arg.FeedbackID, arg.ObjectKey, arg.MimeType, arg.ByteSize, arg.Width, arg.Height, arg.Sha256, ) return err } const createFeedback = `-- name: CreateFeedback :one INSERT INTO feedbacks ( id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash ) VALUES ($1, $2, $3, $4, $5, $6, $7, 'uploading', $8, $9, $10) ON CONFLICT DO NOTHING RETURNING id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash, created_at, updated_at ` type CreateFeedbackParams struct { ID string UserID string Category string Content string Rating *int32 Platform string ClientVersion string RequestID string IdempotencyKey string RequestHash string } func (q *Queries) CreateFeedback(ctx context.Context, arg CreateFeedbackParams) (Feedback, error) { row := q.db.QueryRow(ctx, createFeedback, arg.ID, arg.UserID, arg.Category, arg.Content, arg.Rating, arg.Platform, arg.ClientVersion, arg.RequestID, arg.IdempotencyKey, arg.RequestHash, ) var i Feedback err := row.Scan( &i.ID, &i.UserID, &i.Category, &i.Content, &i.Rating, &i.Platform, &i.ClientVersion, &i.State, &i.RequestID, &i.IdempotencyKey, &i.RequestHash, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const deleteAttachment = `-- name: DeleteAttachment :execrows DELETE FROM feedback_attachments WHERE id = $1 ` func (q *Queries) DeleteAttachment(ctx context.Context, id string) (int64, error) { result, err := q.db.Exec(ctx, deleteAttachment, id) if err != nil { return 0, err } return result.RowsAffected(), nil } const feedbackByID = `-- name: FeedbackByID :one SELECT id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash, created_at, updated_at FROM feedbacks WHERE id = $1 ` func (q *Queries) FeedbackByID(ctx context.Context, id string) (Feedback, error) { row := q.db.QueryRow(ctx, feedbackByID, id) var i Feedback err := row.Scan( &i.ID, &i.UserID, &i.Category, &i.Content, &i.Rating, &i.Platform, &i.ClientVersion, &i.State, &i.RequestID, &i.IdempotencyKey, &i.RequestHash, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const feedbackByIdempotency = `-- name: FeedbackByIdempotency :one SELECT id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash, created_at, updated_at FROM feedbacks WHERE user_id = $1 AND idempotency_key = $2 AND idempotency_key <> '' ` type FeedbackByIdempotencyParams struct { UserID string IdempotencyKey string } func (q *Queries) FeedbackByIdempotency(ctx context.Context, arg FeedbackByIdempotencyParams) (Feedback, error) { row := q.db.QueryRow(ctx, feedbackByIdempotency, arg.UserID, arg.IdempotencyKey) var i Feedback err := row.Scan( &i.ID, &i.UserID, &i.Category, &i.Content, &i.Rating, &i.Platform, &i.ClientVersion, &i.State, &i.RequestID, &i.IdempotencyKey, &i.RequestHash, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const feedbackUsers = `-- name: FeedbackUsers :many SELECT id, name, email, coalesce(nullif(btrim(custom_avatar_url), ''), nullif(btrim(avatar_url), ''), '')::text AS avatar_url FROM users WHERE id = ANY($1::uuid[]) ` type FeedbackUsersRow struct { ID string Name string Email string AvatarUrl string } func (q *Queries) FeedbackUsers(ctx context.Context, userIds []string) ([]FeedbackUsersRow, error) { rows, err := q.db.Query(ctx, feedbackUsers, userIds) if err != nil { return nil, err } defer rows.Close() items := []FeedbackUsersRow{} for rows.Next() { var i FeedbackUsersRow if err := rows.Scan( &i.ID, &i.Name, &i.Email, &i.AvatarUrl, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listAttachments = `-- name: ListAttachments :many SELECT id, feedback_id, object_key, mime_type, byte_size, width, height, sha256, state, created_at FROM feedback_attachments WHERE feedback_id = $1 ORDER BY created_at ASC, id ASC ` func (q *Queries) ListAttachments(ctx context.Context, feedbackID string) ([]FeedbackAttachment, error) { rows, err := q.db.Query(ctx, listAttachments, feedbackID) if err != nil { return nil, err } defer rows.Close() items := []FeedbackAttachment{} for rows.Next() { var i FeedbackAttachment if err := rows.Scan( &i.ID, &i.FeedbackID, &i.ObjectKey, &i.MimeType, &i.ByteSize, &i.Width, &i.Height, &i.Sha256, &i.State, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listFeedbacks = `-- name: ListFeedbacks :many SELECT id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash, created_at, updated_at FROM feedbacks WHERE ($1::uuid[] IS NULL OR feedbacks.user_id = ANY($1::uuid[])) AND ($2::uuid IS NULL OR feedbacks.user_id=$2::uuid) AND ($3::text = '' OR feedbacks.category = $3::text) AND ($4::text = '' OR feedbacks.state = $4::text) ORDER BY created_at DESC, id DESC LIMIT $6::int OFFSET $5::int ` type ListFeedbacksParams struct { VisibleUsers []string UserID *string Category string State string PageOffset int32 PageLimit int32 } func (q *Queries) ListFeedbacks(ctx context.Context, arg ListFeedbacksParams) ([]Feedback, error) { rows, err := q.db.Query(ctx, listFeedbacks, arg.VisibleUsers, arg.UserID, arg.Category, arg.State, arg.PageOffset, arg.PageLimit, ) if err != nil { return nil, err } defer rows.Close() items := []Feedback{} for rows.Next() { var i Feedback if err := rows.Scan( &i.ID, &i.UserID, &i.Category, &i.Content, &i.Rating, &i.Platform, &i.ClientVersion, &i.State, &i.RequestID, &i.IdempotencyKey, &i.RequestHash, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listStaleAttachments = `-- name: ListStaleAttachments :many SELECT id, feedback_id, object_key, mime_type, byte_size, width, height, sha256, state, created_at FROM feedback_attachments WHERE state IN ('pending', 'failed') AND created_at < $1 ORDER BY created_at ASC LIMIT $2 ` type ListStaleAttachmentsParams struct { CreatedAt time.Time Limit int32 } func (q *Queries) ListStaleAttachments(ctx context.Context, arg ListStaleAttachmentsParams) ([]FeedbackAttachment, error) { rows, err := q.db.Query(ctx, listStaleAttachments, arg.CreatedAt, arg.Limit) if err != nil { return nil, err } defer rows.Close() items := []FeedbackAttachment{} for rows.Next() { var i FeedbackAttachment if err := rows.Scan( &i.ID, &i.FeedbackID, &i.ObjectKey, &i.MimeType, &i.ByteSize, &i.Width, &i.Height, &i.Sha256, &i.State, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const markStaleUploading = `-- name: MarkStaleUploading :execrows WITH stale AS ( UPDATE feedbacks AS f SET state = 'failed', updated_at = now() WHERE f.state = 'uploading' AND f.created_at < $1 RETURNING id ) UPDATE feedback_attachments AS a SET state = 'failed' FROM stale WHERE a.feedback_id = stale.id AND a.state <> 'failed' ` func (q *Queries) MarkStaleUploading(ctx context.Context, createdAt time.Time) (int64, error) { result, err := q.db.Exec(ctx, markStaleUploading, createdAt) if err != nil { return 0, err } return result.RowsAffected(), nil } const setAttachmentFailed = `-- name: SetAttachmentFailed :execrows UPDATE feedback_attachments SET state = 'failed' WHERE id = $1 AND feedback_id = $2 AND state <> 'failed' ` type SetAttachmentFailedParams struct { ID string FeedbackID string } func (q *Queries) SetAttachmentFailed(ctx context.Context, arg SetAttachmentFailedParams) (int64, error) { result, err := q.db.Exec(ctx, setAttachmentFailed, arg.ID, arg.FeedbackID) if err != nil { return 0, err } return result.RowsAffected(), nil } const setAttachmentReady = `-- name: SetAttachmentReady :execrows UPDATE feedback_attachments SET state = 'ready' WHERE id = $1 AND feedback_id = $2 AND state = 'pending' ` type SetAttachmentReadyParams struct { ID string FeedbackID string } func (q *Queries) SetAttachmentReady(ctx context.Context, arg SetAttachmentReadyParams) (int64, error) { result, err := q.db.Exec(ctx, setAttachmentReady, arg.ID, arg.FeedbackID) if err != nil { return 0, err } return result.RowsAffected(), nil } const setFeedbackState = `-- name: SetFeedbackState :execrows UPDATE feedbacks SET state = $2, updated_at = now() WHERE id = $1 ` type SetFeedbackStateParams struct { ID string State string } func (q *Queries) SetFeedbackState(ctx context.Context, arg SetFeedbackStateParams) (int64, error) { result, err := q.db.Exec(ctx, setFeedbackState, arg.ID, arg.State) if err != nil { return 0, err } return result.RowsAffected(), nil } const updateFeedbackState = `-- name: UpdateFeedbackState :one UPDATE feedbacks SET state = $2, updated_at = now() WHERE id = $1 RETURNING id, user_id, category, content, rating, platform, client_version, state, request_id, idempotency_key, request_hash, created_at, updated_at ` type UpdateFeedbackStateParams struct { ID string State string } func (q *Queries) UpdateFeedbackState(ctx context.Context, arg UpdateFeedbackStateParams) (Feedback, error) { row := q.db.QueryRow(ctx, updateFeedbackState, arg.ID, arg.State) var i Feedback err := row.Scan( &i.ID, &i.UserID, &i.Category, &i.Content, &i.Rating, &i.Platform, &i.ClientVersion, &i.State, &i.RequestID, &i.IdempotencyKey, &i.RequestHash, &i.CreatedAt, &i.UpdatedAt, ) return i, err }