ЛР 4: вложения в S3 и двусторонняя сверка хранилищ
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: messages_attachments.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createMessagesAttachments = `-- name: CreateMessagesAttachments :execrows
|
||||
INSERT INTO messages_attachments (message_id, attachment_id, chat_id, position)
|
||||
SELECT $1, $2, $3, $4
|
||||
FROM attachments
|
||||
WHERE id = $2 AND chat_id = $3
|
||||
`
|
||||
|
||||
type CreateMessagesAttachmentsParams struct {
|
||||
MessageID pgtype.UUID
|
||||
AttachmentID pgtype.UUID
|
||||
ChatID pgtype.UUID
|
||||
Position int16
|
||||
}
|
||||
|
||||
func (q *Queries) CreateMessagesAttachments(ctx context.Context, arg CreateMessagesAttachmentsParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, createMessagesAttachments,
|
||||
arg.MessageID,
|
||||
arg.AttachmentID,
|
||||
arg.ChatID,
|
||||
arg.Position,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const getMessagesAttachments = `-- name: GetMessagesAttachments :many
|
||||
SELECT attachment_id, position
|
||||
FROM messages_attachments
|
||||
WHERE message_id = $1
|
||||
ORDER BY position ASC
|
||||
`
|
||||
|
||||
type GetMessagesAttachmentsRow struct {
|
||||
AttachmentID pgtype.UUID
|
||||
Position int16
|
||||
}
|
||||
|
||||
func (q *Queries) GetMessagesAttachments(ctx context.Context, messageID pgtype.UUID) ([]GetMessagesAttachmentsRow, error) {
|
||||
rows, err := q.db.Query(ctx, getMessagesAttachments, messageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetMessagesAttachmentsRow
|
||||
for rows.Next() {
|
||||
var i GetMessagesAttachmentsRow
|
||||
if err := rows.Scan(&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
|
||||
}
|
||||
Reference in New Issue
Block a user