1-- name: CreatePostComment :exec
2INSERT INTO
3 post_comment (body, user_id, post_id, parent_id)
4VALUES
5 (?, ?, ?, ?);
6
7-- name: CreatePostCommentNoParent :exec
8INSERT INTO
9 post_comment (body, user_id, post_id, parent_id)
10VALUES
11 (?, ?, ?, NULL);
12
13-- name: GetPostCommentsByPostID :many
14SELECT
15 post_comment.id,
16 post_comment.body,
17 user.username,
18 COUNT(DISTINCT user_like_post_comment.id) AS like_count,
19 post_comment.parent_id,
20 UNIX_TIMESTAMP (post_comment.created_at) AS created_at
21FROM
22 post_comment
23 LEFT JOIN user_like_post_comment ON post_comment.id = user_like_post_comment.post_comment_id
24 AND user_like_post_comment.status = 'like'
25 LEFT JOIN user ON post_comment.user_id = user.id
26WHERE
27 post_comment.post_id = ?
28GROUP BY
29 post_comment.id,
30 user.username
31ORDER BY
32 post_comment.created_at DESC;
33
34-- name: GetPostCommentsByID :one
35SELECT
36 post_comment.id,
37 post_comment.body,
38 user.username,
39 COUNT(DISTINCT user_like_post_comment.id) AS like_count,
40 post_comment.parent_id,
41 UNIX_TIMESTAMP (post_comment.created_at) AS created_at
42FROM
43 post_comment
44 LEFT JOIN user_like_post_comment ON post_comment.id = user_like_post_comment.post_comment_id
45 AND user_like_post_comment.status = 'like'
46 LEFT JOIN user ON post_comment.user_id = user.id
47WHERE
48 post_comment.id = ?
49GROUP BY
50 post_comment.id,
51 user.username
52ORDER BY
53 post_comment.created_at DESC;
54
55-- name: GetPostCommentParentInPost :one
56SELECT
57 post_comment.body,
58 post_comment.user_id
59FROM
60 post_comment
61WHERE
62 post_comment.post_id = ?
63 AND post_comment.id = ?;
64
65-- name: GetCommentsForSitemap :many
66SELECT
67 post_comment.id,
68 UNIX_TIMESTAMP (post_comment.created_at) AS created_at
69FROM
70 post_comment
71WHERE
72 post_comment.post_id = ?
73ORDER BY
74 post_comment.created_at DESC;