Files
mtusi2026lab4/internal/db/attachments.sql.go
T

228 lines
4.9 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: attachments.sql
package db
import (
"context"
"github.com/google/uuid"
)
const createAttachment = `-- name: CreateAttachment :one
INSERT INTO attachments (
id,
chat_id,
owner_id,
s3_key,
filename,
content_type,
size_bytes,
sha256,
status,
error_code
)
SELECT
$1::uuid,
$2::uuid,
$3::uuid,
$4::text,
$5::text,
$6::attachment_content_type,
$7::int,
$8::text,
$9::attachment_status,
$10::text
WHERE EXISTS (
SELECT 1 FROM chat_members
WHERE chat_id = $2
AND user_id = $3
)
RETURNING id, chat_id, owner_id, s3_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
S3Key string
Filename string
ContentType AttachmentContentType
SizeBytes int
Sha256 string
Status AttachmentStatus
ErrorCode 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.S3Key,
arg.Filename,
arg.ContentType,
arg.SizeBytes,
arg.Sha256,
arg.Status,
arg.ErrorCode,
)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.S3Key,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createMessageAttachment = `-- name: CreateMessageAttachment :exec
INSERT INTO message_attachments (
message_id,
attachment_id,
position
) VALUES (
$1,
$2,
$3
)
`
type CreateMessageAttachmentParams struct {
MessageID uuid.UUID
AttachmentID uuid.UUID
Position int
}
func (q *Queries) CreateMessageAttachment(ctx context.Context, arg CreateMessageAttachmentParams) error {
_, err := q.db.Exec(ctx, createMessageAttachment, arg.MessageID, arg.AttachmentID, arg.Position)
return err
}
const getAttachmentByID = `-- name: GetAttachmentByID :one
SELECT id, chat_id, owner_id, s3_key, filename, content_type, size_bytes, sha256, status, error_code, created_at, updated_at FROM attachments
WHERE id = $1::uuid
`
func (q *Queries) GetAttachmentByID(ctx context.Context, dollar_1 uuid.UUID) (Attachment, error) {
row := q.db.QueryRow(ctx, getAttachmentByID, dollar_1)
var i Attachment
err := row.Scan(
&i.ID,
&i.ChatID,
&i.OwnerID,
&i.S3Key,
&i.Filename,
&i.ContentType,
&i.SizeBytes,
&i.Sha256,
&i.Status,
&i.ErrorCode,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listAttachmentsByIDs = `-- name: ListAttachmentsByIDs :many
SELECT status
FROM attachments
WHERE chat_id = $1::uuid
AND id = ANY($2::uuid[])
`
type ListAttachmentsByIDsParams struct {
ChatID uuid.UUID
Ids []uuid.UUID
}
func (q *Queries) ListAttachmentsByIDs(ctx context.Context, arg ListAttachmentsByIDsParams) ([]AttachmentStatus, error) {
rows, err := q.db.Query(ctx, listAttachmentsByIDs, arg.ChatID, arg.Ids)
if err != nil {
return nil, err
}
defer rows.Close()
items := []AttachmentStatus{}
for rows.Next() {
var status AttachmentStatus
if err := rows.Scan(&status); err != nil {
return nil, err
}
items = append(items, status)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMessageAttachmentIDs = `-- name: ListMessageAttachmentIDs :many
SELECT attachment_id
FROM message_attachments
WHERE message_id = $1::uuid
ORDER BY position
`
func (q *Queries) ListMessageAttachmentIDs(ctx context.Context, messageID uuid.UUID) ([]uuid.UUID, error) {
rows, err := q.db.Query(ctx, listMessageAttachmentIDs, 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 listMessageAttachmentsByMessageIDs = `-- name: ListMessageAttachmentsByMessageIDs :many
SELECT message_id, attachment_id
FROM message_attachments
WHERE message_id = ANY($1::uuid[])
ORDER BY message_id, position
`
type ListMessageAttachmentsByMessageIDsRow struct {
MessageID uuid.UUID
AttachmentID uuid.UUID
}
func (q *Queries) ListMessageAttachmentsByMessageIDs(ctx context.Context, messageIds []uuid.UUID) ([]ListMessageAttachmentsByMessageIDsRow, error) {
rows, err := q.db.Query(ctx, listMessageAttachmentsByMessageIDs, messageIds)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListMessageAttachmentsByMessageIDsRow{}
for rows.Next() {
var i ListMessageAttachmentsByMessageIDsRow
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
}