forked from mtusi2026/mtusi2026lab4
ЛР 4: вложения в S3 и двусторонняя сверка хранилищ
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
-- 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 *;
|
||||
|
||||
-- name: GetAttachmentForUser :one
|
||||
SELECT a.*
|
||||
FROM attachments AS a
|
||||
JOIN chat_members AS cm ON cm.chat_id = a.chat_id
|
||||
WHERE a.id = sqlc.arg(attachment_id)
|
||||
AND cm.user_id = sqlc.arg(user_id);
|
||||
|
||||
|
||||
-- name: GetAttachmentsForMessages :many
|
||||
SELECT message_id, attachment_id, position
|
||||
FROM messages_attachments
|
||||
WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[])
|
||||
ORDER BY message_id, position;
|
||||
|
||||
|
||||
-- name: AttachmentExistsByObjectKey :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM attachments
|
||||
WHERE object_key = sqlc.arg(object_key)
|
||||
);
|
||||
|
||||
-- name: TryLockAttachmentObjectKey :one
|
||||
SELECT pg_try_advisory_xact_lock(
|
||||
hashtextextended(sqlc.arg(object_key)::text, 0)
|
||||
)::boolean AS locked;
|
||||
|
||||
-- name: ListAttachmentKeys :many
|
||||
SELECT id, object_key, created_at
|
||||
FROM attachments
|
||||
WHERE object_key > sqlc.arg(after_key)
|
||||
ORDER BY object_key
|
||||
LIMIT sqlc.arg(page_size);
|
||||
|
||||
-- name: GetAttachmentByID :one
|
||||
SELECT * FROM attachments WHERE id = sqlc.arg(attachment_id);
|
||||
Reference in New Issue
Block a user