Files
mtusi2026lab4/internal/database/sqlc/attachments.sql.go
T

208 lines
5.0 KiB
Go

// 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
)
`
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
INSERT INTO attachments
(chat_id, owner_id, filename, object_key, content_type, size_bytes, sha256)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, chat_id, owner_id, filename, object_key, content_type, size_bytes, sha256, created_at, updated_at
`
type CreateAttachmentParams struct {
ChatID pgtype.UUID
OwnerID pgtype.UUID
Filename string
ObjectKey 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.ChatID,
arg.OwnerID,
arg.Filename,
arg.ObjectKey,
arg.ContentType,
arg.SizeBytes,
arg.Sha256,
)
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,
)
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 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,
)
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
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,
)
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 string
PageSize int32
}
type ListAttachmentKeysRow struct {
ID pgtype.UUID
ObjectKey string
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
}