-- name: ChargeAttachment :one UPDATE users SET attachment_count=attachment_count+1 WHERE id=$1 AND attachment_count<10000 RETURNING id; -- name: InsertAttachment :one INSERT INTO attachments(id,chat_id,owner_id,filename,content_type,size_bytes,sha256,status) VALUES($1,$2,$3,$4,$5,$6,$7,'uploading') RETURNING *; -- name: GetAttachment :one SELECT * FROM attachments WHERE id=$1 FOR SHARE; -- name: SetAttachmentStatus :execrows UPDATE attachments SET status=$2,updated_at=clock_timestamp() WHERE id=$1 AND status=$3 AND pipeline_version=0; -- name: InsertMessageAttachment :exec INSERT INTO message_attachments(message_id,attachment_id,ordinal) VALUES($1,$2,$3); -- name: MessageAttachments :many SELECT attachment_id FROM message_attachments WHERE message_id=$1 ORDER BY ordinal LIMIT 10; -- name: ReconcileAttachments :many SELECT * FROM attachments WHERE id>$1 ORDER BY id LIMIT 101;