// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: attachments.sql package sqlc import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const attachmentExistsByObjectKey = `-- name: AttachmentExistsByObjectKey :one SELECT EXISTS ( SELECT 1 FROM attachments WHERE object_key = $1::text OR staging_key = $1::text UNION ALL SELECT 1 FROM attachment_variants WHERE object_key = $1::text UNION ALL SELECT 1 FROM attachment_jobs WHERE published_original_key = $1::text ) ` func (q *Queries) AttachmentExistsByObjectKey(ctx context.Context, objectKey string) (bool, error) { row := q.db.QueryRow(ctx, attachmentExistsByObjectKey, objectKey) var exists bool err := row.Scan(&exists) return exists, err } const createAttachment = `-- name: CreateAttachment :one WITH legacy AS ( INSERT INTO attachments (chat_id, owner_id, filename, object_key, staging_key, content_type, size_bytes, sha256) VALUES ($1, $2, $3, $4::text, $4::text, $5, $6, $7) 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 ), job AS ( INSERT INTO attachment_jobs (attachment_id, pipeline_version) SELECT id, pipeline_version FROM legacy RETURNING id, attachment_id, pipeline_version, attempts_started, max_attempts, next_attempt_at, lease_generation, lease_until, created_at, updated_at, published_original_key ), event AS ( INSERT INTO outbox (job_id, payload, dedup_key) SELECT id, attachment_job_payload(id, attachment_id, pipeline_version, 1, created_at), 'initial/' || id FROM job RETURNING job_id ) SELECT legacy.id, legacy.chat_id, legacy.owner_id, legacy.filename, legacy.object_key, legacy.content_type, legacy.size_bytes, legacy.sha256, legacy.created_at, legacy.updated_at, legacy.status, legacy.error_code, legacy.staging_key, legacy.pipeline_version FROM legacy CROSS JOIN event ` type CreateAttachmentParams struct { ChatID pgtype.UUID OwnerID pgtype.UUID Filename string ObjectKey string ContentType string SizeBytes int64 Sha256 string } type CreateAttachmentRow struct { ID pgtype.UUID ChatID pgtype.UUID OwnerID pgtype.UUID Filename string ObjectKey pgtype.Text ContentType string SizeBytes int64 Sha256 string CreatedAt pgtype.Timestamptz UpdatedAt pgtype.Timestamptz Status string ErrorCode pgtype.Text StagingKey pgtype.Text PipelineVersion int32 } // Compatibility for the synchronous API until CreateQueuedAttachment is wired in. func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) (CreateAttachmentRow, error) { row := q.db.QueryRow(ctx, createAttachment, arg.ChatID, arg.OwnerID, arg.Filename, arg.ObjectKey, arg.ContentType, arg.SizeBytes, arg.Sha256, ) var i CreateAttachmentRow 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 createQueuedAttachment = `-- name: CreateQueuedAttachment :one INSERT INTO attachments ( id, chat_id, owner_id, filename, content_type, size_bytes, sha256, staging_key, status ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, 'queued' ) 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 CreateQueuedAttachmentParams struct { ID pgtype.UUID ChatID pgtype.UUID OwnerID pgtype.UUID Filename string ContentType string SizeBytes int64 Sha256 string StagingKey pgtype.Text } func (q *Queries) CreateQueuedAttachment(ctx context.Context, arg CreateQueuedAttachmentParams) (Attachment, error) { row := q.db.QueryRow(ctx, createQueuedAttachment, arg.ID, arg.ChatID, arg.OwnerID, arg.Filename, arg.ContentType, arg.SizeBytes, arg.Sha256, arg.StagingKey, ) 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 getAttachmentByID = `-- name: GetAttachmentByID :one SELECT id, chat_id, owner_id, filename, object_key, content_type, size_bytes, sha256, created_at, updated_at, status, error_code, staging_key, pipeline_version FROM attachments WHERE id = $1 ` func (q *Queries) GetAttachmentByID(ctx context.Context, attachmentID pgtype.UUID) (Attachment, error) { row := q.db.QueryRow(ctx, getAttachmentByID, attachmentID) 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 getAttachmentForUser = `-- name: GetAttachmentForUser :one SELECT a.id, a.chat_id, a.owner_id, a.filename, a.object_key, a.content_type, a.size_bytes, a.sha256, a.created_at, a.updated_at, a.status, a.error_code, a.staging_key, a.pipeline_version FROM attachments AS a JOIN chat_members AS cm ON cm.chat_id = a.chat_id WHERE a.id = $1 AND cm.user_id = $2 ` type GetAttachmentForUserParams struct { AttachmentID pgtype.UUID UserID pgtype.UUID } func (q *Queries) GetAttachmentForUser(ctx context.Context, arg GetAttachmentForUserParams) (Attachment, error) { row := q.db.QueryRow(ctx, getAttachmentForUser, arg.AttachmentID, arg.UserID) 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 getAttachmentsForMessages = `-- name: GetAttachmentsForMessages :many SELECT message_id, attachment_id, position FROM messages_attachments WHERE message_id = ANY($1::uuid[]) ORDER BY message_id, position ` type GetAttachmentsForMessagesRow struct { MessageID pgtype.UUID AttachmentID pgtype.UUID Position int16 } func (q *Queries) GetAttachmentsForMessages(ctx context.Context, messageIds []pgtype.UUID) ([]GetAttachmentsForMessagesRow, error) { rows, err := q.db.Query(ctx, getAttachmentsForMessages, messageIds) if err != nil { return nil, err } defer rows.Close() var items []GetAttachmentsForMessagesRow for rows.Next() { var i GetAttachmentsForMessagesRow if err := rows.Scan(&i.MessageID, &i.AttachmentID, &i.Position); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listAttachmentKeys = `-- name: ListAttachmentKeys :many SELECT id, object_key, created_at FROM attachments WHERE object_key > $1 ORDER BY object_key LIMIT $2 ` type ListAttachmentKeysParams struct { AfterKey pgtype.Text PageSize int32 } type ListAttachmentKeysRow struct { ID pgtype.UUID ObjectKey pgtype.Text CreatedAt pgtype.Timestamptz } func (q *Queries) ListAttachmentKeys(ctx context.Context, arg ListAttachmentKeysParams) ([]ListAttachmentKeysRow, error) { rows, err := q.db.Query(ctx, listAttachmentKeys, arg.AfterKey, arg.PageSize) if err != nil { return nil, err } defer rows.Close() var items []ListAttachmentKeysRow for rows.Next() { var i ListAttachmentKeysRow if err := rows.Scan(&i.ID, &i.ObjectKey, &i.CreatedAt); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const tryLockAttachmentObjectKey = `-- name: TryLockAttachmentObjectKey :one SELECT pg_try_advisory_xact_lock( hashtextextended($1::text, 0) )::boolean AS locked ` func (q *Queries) TryLockAttachmentObjectKey(ctx context.Context, objectKey string) (bool, error) { row := q.db.QueryRow(ctx, tryLockAttachmentObjectKey, objectKey) var locked bool err := row.Scan(&locked) return locked, err }