// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: attachments.sql package queries import ( "context" "github.com/google/uuid" ) const chargeAttachment = `-- name: ChargeAttachment :one UPDATE users SET attachment_count=attachment_count+1 WHERE id=$1 AND attachment_count<10000 RETURNING id ` func (q *Queries) ChargeAttachment(ctx context.Context, id uuid.UUID) (uuid.UUID, error) { row := q.db.QueryRow(ctx, chargeAttachment, id) var id_2 uuid.UUID err := row.Scan(&id_2) return id_2, err } const getAttachment = `-- name: GetAttachment :one SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at FROM attachments WHERE id=$1 FOR SHARE ` func (q *Queries) GetAttachment(ctx context.Context, id uuid.UUID) (Attachment, error) { row := q.db.QueryRow(ctx, getAttachment, id) var i Attachment err := row.Scan( &i.ID, &i.ChatID, &i.OwnerID, &i.Filename, &i.ContentType, &i.SizeBytes, &i.Sha256, &i.Status, &i.PipelineVersion, &i.ErrorCode, &i.Variants, &i.StagingExpired, &i.StagingCleaned, &i.CreatedAt, &i.UpdatedAt, &i.AcceptedAt, &i.FirstReadyAt, ) return i, err } const insertAttachment = `-- name: InsertAttachment :one INSERT INTO attachments(id,chat_id,owner_id,filename,content_type,size_bytes,sha256,status) VALUES($1,$2,$3,$4,$5,$6,$7,'uploading') RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at ` type InsertAttachmentParams struct { ID uuid.UUID ChatID uuid.UUID OwnerID uuid.UUID Filename string ContentType string SizeBytes int64 Sha256 string } func (q *Queries) InsertAttachment(ctx context.Context, arg InsertAttachmentParams) (Attachment, error) { row := q.db.QueryRow(ctx, insertAttachment, arg.ID, arg.ChatID, arg.OwnerID, arg.Filename, arg.ContentType, arg.SizeBytes, arg.Sha256, ) var i Attachment err := row.Scan( &i.ID, &i.ChatID, &i.OwnerID, &i.Filename, &i.ContentType, &i.SizeBytes, &i.Sha256, &i.Status, &i.PipelineVersion, &i.ErrorCode, &i.Variants, &i.StagingExpired, &i.StagingCleaned, &i.CreatedAt, &i.UpdatedAt, &i.AcceptedAt, &i.FirstReadyAt, ) return i, err } const insertMessageAttachment = `-- name: InsertMessageAttachment :exec INSERT INTO message_attachments(message_id,attachment_id,ordinal) VALUES($1,$2,$3) ` type InsertMessageAttachmentParams struct { MessageID uuid.UUID AttachmentID uuid.UUID Ordinal int32 } func (q *Queries) InsertMessageAttachment(ctx context.Context, arg InsertMessageAttachmentParams) error { _, err := q.db.Exec(ctx, insertMessageAttachment, arg.MessageID, arg.AttachmentID, arg.Ordinal) return err } const messageAttachments = `-- name: MessageAttachments :many SELECT attachment_id FROM message_attachments WHERE message_id=$1 ORDER BY ordinal LIMIT 10 ` func (q *Queries) MessageAttachments(ctx context.Context, messageID uuid.UUID) ([]uuid.UUID, error) { rows, err := q.db.Query(ctx, messageAttachments, messageID) if err != nil { return nil, err } defer rows.Close() items := []uuid.UUID{} for rows.Next() { var attachment_id uuid.UUID if err := rows.Scan(&attachment_id); err != nil { return nil, err } items = append(items, attachment_id) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const reconcileAttachments = `-- name: ReconcileAttachments :many SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at FROM attachments WHERE id>$1 ORDER BY id LIMIT 101 ` func (q *Queries) ReconcileAttachments(ctx context.Context, id uuid.UUID) ([]Attachment, error) { rows, err := q.db.Query(ctx, reconcileAttachments, id) if err != nil { return nil, err } defer rows.Close() items := []Attachment{} for rows.Next() { var i Attachment if err := rows.Scan( &i.ID, &i.ChatID, &i.OwnerID, &i.Filename, &i.ContentType, &i.SizeBytes, &i.Sha256, &i.Status, &i.PipelineVersion, &i.ErrorCode, &i.Variants, &i.StagingExpired, &i.StagingCleaned, &i.CreatedAt, &i.UpdatedAt, &i.AcceptedAt, &i.FirstReadyAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const setAttachmentStatus = `-- name: SetAttachmentStatus :execrows UPDATE attachments SET status=$2,updated_at=clock_timestamp() WHERE id=$1 AND status=$3 AND pipeline_version=0 ` type SetAttachmentStatusParams struct { ID uuid.UUID Status string Status_2 string } func (q *Queries) SetAttachmentStatus(ctx context.Context, arg SetAttachmentStatusParams) (int64, error) { result, err := q.db.Exec(ctx, setAttachmentStatus, arg.ID, arg.Status, arg.Status_2) if err != nil { return 0, err } return result.RowsAffected(), nil }