forked from mtusi2026/mtusi2026lab4
refactor(db): use int for attachment size and add lookup query
This commit is contained in:
@@ -31,7 +31,7 @@ SELECT
|
||||
$4::text,
|
||||
$5::text,
|
||||
$6::text,
|
||||
$7::bigint,
|
||||
$7::int,
|
||||
$8::text,
|
||||
$9::text,
|
||||
$10::text
|
||||
@@ -50,7 +50,7 @@ type CreateAttachmentParams struct {
|
||||
S3Key string
|
||||
Filename string
|
||||
ContentType string
|
||||
SizeBytes int64
|
||||
SizeBytes int
|
||||
Sha256 string
|
||||
Status string
|
||||
ErrorCode string
|
||||
@@ -102,7 +102,7 @@ INSERT INTO message_attachments (
|
||||
type CreateMessageAttachmentParams struct {
|
||||
MessageID uuid.UUID
|
||||
AttachmentID uuid.UUID
|
||||
Position int32
|
||||
Position int
|
||||
}
|
||||
|
||||
func (q *Queries) CreateMessageAttachment(ctx context.Context, arg CreateMessageAttachmentParams) error {
|
||||
@@ -110,6 +110,31 @@ func (q *Queries) CreateMessageAttachment(ctx context.Context, arg CreateMessage
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user