Files
mtusi2026lab5/internal/storage/postgres/internal/sqlcgen/attachments.sql.go
T
2026-10-29 23:36:12 +03:00

368 lines
8.2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: attachments.sql
package sqlcgen
import (
"context"
"time"
"github.com/google/uuid"
)
const attachToMessage = `-- name: AttachToMessage :exec
INSERT INTO message_attachments (message_id, attachment_id, position)
VALUES ($1, $2, $3)
`
type AttachToMessageParams struct {
MessageID uuid.UUID
AttachmentID uuid.UUID
Position int16
}
func (q *Queries) AttachToMessage(ctx context.Context, arg AttachToMessageParams) error {
_, err := q.db.Exec(ctx, attachToMessage, arg.MessageID, arg.AttachmentID, arg.Position)
return err
}
const createAttachment = `-- name: CreateAttachment :one
INSERT INTO attachments (
id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256, status
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
'pending'
)
RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at
`
type CreateAttachmentParams struct {
ID uuid.UUID
ChatID uuid.UUID
OwnerID uuid.UUID
ObjectKey string
Filename string
ContentType string
SizeBytes int64
Sha256 string
}
func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) (Attachment, error) {
row := q.db.QueryRow(ctx, createAttachment,
arg.ID,
arg.ChatID,
arg.OwnerID,
arg.ObjectKey,
arg.Filename,
arg.ContentType,
arg.SizeBytes,
arg.Sha256,
)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.ObjectKey,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deletePendingAttachment = `-- name: DeletePendingAttachment :exec
DELETE FROM attachments
WHERE id = $1
AND status = 'pending'
`
func (q *Queries) DeletePendingAttachment(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, deletePendingAttachment, id)
return err
}
const getAttachmentForMember = `-- name: GetAttachmentForMember :one
SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type,
a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at
FROM attachments a
JOIN chat_members cm
ON cm.chat_id = a.chat_id
AND cm.user_id = $1
WHERE a.id = $2
`
type GetAttachmentForMemberParams struct {
UserID uuid.UUID
ID uuid.UUID
}
func (q *Queries) GetAttachmentForMember(ctx context.Context, arg GetAttachmentForMemberParams) (Attachment, error) {
row := q.db.QueryRow(ctx, getAttachmentForMember, arg.UserID, arg.ID)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.ObjectKey,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getAttachmentForOwner = `-- name: GetAttachmentForOwner :one
SELECT a.id, a.chat_id, a.owner_id, a.object_key, a.filename, a.content_type,
a.size_bytes, a.sha256, a.status, a.error_code, a.created_at, a.updated_at
FROM attachments a
JOIN chat_members cm
ON cm.chat_id = a.chat_id
AND cm.user_id = a.owner_id
WHERE a.id = $1
AND a.owner_id = $2
`
type GetAttachmentForOwnerParams struct {
ID uuid.UUID
OwnerID uuid.UUID
}
func (q *Queries) GetAttachmentForOwner(ctx context.Context, arg GetAttachmentForOwnerParams) (Attachment, error) {
row := q.db.QueryRow(ctx, getAttachmentForOwner, arg.ID, arg.OwnerID)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.ObjectKey,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listAttachmentKeys = `-- name: ListAttachmentKeys :many
SELECT id, object_key, status, created_at
FROM attachments
ORDER BY id
LIMIT $2 OFFSET $1
`
type ListAttachmentKeysParams struct {
RowOffset int32
RowLimit int32
}
type ListAttachmentKeysRow struct {
ID uuid.UUID
ObjectKey string
Status string
CreatedAt time.Time
}
func (q *Queries) ListAttachmentKeys(ctx context.Context, arg ListAttachmentKeysParams) ([]ListAttachmentKeysRow, error) {
rows, err := q.db.Query(ctx, listAttachmentKeys, arg.RowOffset, arg.RowLimit)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListAttachmentKeysRow{}
for rows.Next() {
var i ListAttachmentKeysRow
if err := rows.Scan(
&i.ID,
&i.ObjectKey,
&i.Status,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listAttachmentStatesForChat = `-- name: ListAttachmentStatesForChat :many
SELECT id, status
FROM attachments
WHERE chat_id = $1
AND id = ANY($2::uuid[])
`
type ListAttachmentStatesForChatParams struct {
ChatID uuid.UUID
Ids []uuid.UUID
}
type ListAttachmentStatesForChatRow struct {
ID uuid.UUID
Status string
}
func (q *Queries) ListAttachmentStatesForChat(ctx context.Context, arg ListAttachmentStatesForChatParams) ([]ListAttachmentStatesForChatRow, error) {
rows, err := q.db.Query(ctx, listAttachmentStatesForChat, arg.ChatID, arg.Ids)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListAttachmentStatesForChatRow{}
for rows.Next() {
var i ListAttachmentStatesForChatRow
if err := rows.Scan(&i.ID, &i.Status); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMessageAttachments = `-- name: ListMessageAttachments :many
SELECT message_id, attachment_id
FROM message_attachments
WHERE message_id = ANY($1::uuid[])
ORDER BY message_id, position
`
type ListMessageAttachmentsRow struct {
MessageID uuid.UUID
AttachmentID uuid.UUID
}
func (q *Queries) ListMessageAttachments(ctx context.Context, messageIds []uuid.UUID) ([]ListMessageAttachmentsRow, error) {
rows, err := q.db.Query(ctx, listMessageAttachments, messageIds)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListMessageAttachmentsRow{}
for rows.Next() {
var i ListMessageAttachmentsRow
if err := rows.Scan(&i.MessageID, &i.AttachmentID); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listStalePendingAttachments = `-- name: ListStalePendingAttachments :many
SELECT id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at
FROM attachments
WHERE status = 'pending'
AND created_at < $1
ORDER BY created_at
LIMIT $2
`
type ListStalePendingAttachmentsParams struct {
CreatedBefore time.Time
RowLimit int32
}
func (q *Queries) ListStalePendingAttachments(ctx context.Context, arg ListStalePendingAttachmentsParams) ([]Attachment, error) {
rows, err := q.db.Query(ctx, listStalePendingAttachments, arg.CreatedBefore, arg.RowLimit)
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.ObjectKey,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&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 markAttachmentReady = `-- name: MarkAttachmentReady :one
UPDATE attachments
SET status = 'ready',
object_key = $1,
updated_at = now()
WHERE id = $2
AND status = 'pending'
RETURNING id, chat_id, owner_id, object_key, filename, content_type, size_bytes, sha256,
status, error_code, created_at, updated_at
`
type MarkAttachmentReadyParams struct {
ObjectKey string
ID uuid.UUID
}
func (q *Queries) MarkAttachmentReady(ctx context.Context, arg MarkAttachmentReadyParams) (Attachment, error) {
row := q.db.QueryRow(ctx, markAttachmentReady, arg.ObjectKey, arg.ID)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.ObjectKey,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}