@@ -61,6 +61,52 @@ SET
|
||||
updated_at = sqlc.arg(updated_at)
|
||||
WHERE id = sqlc.arg(id);
|
||||
|
||||
-- name: CreatePostImage :exec
|
||||
INSERT INTO post_images (
|
||||
id, post_id, object_key, public_url, description, position, width, height, created_at
|
||||
)
|
||||
VALUES (
|
||||
sqlc.arg(id),
|
||||
sqlc.arg(post_id),
|
||||
sqlc.arg(object_key),
|
||||
sqlc.arg(public_url),
|
||||
sqlc.arg(description),
|
||||
sqlc.arg(position),
|
||||
sqlc.arg(width),
|
||||
sqlc.arg(height),
|
||||
sqlc.arg(created_at)
|
||||
);
|
||||
|
||||
-- name: DeletePostImages :exec
|
||||
DELETE FROM post_images
|
||||
WHERE post_id = sqlc.arg(post_id);
|
||||
|
||||
-- name: ListPostImages :many
|
||||
SELECT
|
||||
id, post_id, object_key, public_url, description, position, width, height, created_at
|
||||
FROM post_images
|
||||
WHERE post_id = sqlc.arg(post_id)
|
||||
ORDER BY position;
|
||||
|
||||
-- name: ListPostThreadImages :many
|
||||
WITH RECURSIVE thread AS (
|
||||
SELECT p.id
|
||||
FROM posts p
|
||||
WHERE p.id = sqlc.arg(root_id) AND p.parent_id IS NULL
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT child.id
|
||||
FROM posts child
|
||||
JOIN thread parent ON child.parent_id = parent.id
|
||||
)
|
||||
SELECT
|
||||
images.id, images.post_id, images.object_key, images.public_url,
|
||||
images.description, images.position, images.width, images.height, images.created_at
|
||||
FROM post_images images
|
||||
JOIN thread ON thread.id = images.post_id
|
||||
ORDER BY images.post_id, images.position;
|
||||
|
||||
-- name: UpdateRootPostState :execrows
|
||||
UPDATE posts
|
||||
SET
|
||||
|
||||
Reference in New Issue
Block a user